Skip to content

Commit

Permalink
Fix panic on empty attached_text form values
Browse files Browse the repository at this point in the history
Resolves #470
  • Loading branch information
martinhpedersen committed Jan 21, 2025
1 parent 32448b1 commit 4dc5577
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/forms/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,16 @@ func (b messageBuilder) buildAttachments() []*fbb.File {
if !strings.HasPrefix(k, "attached_text") {
continue
}
if strings.TrimSpace(b.FormValues[k]) == "" {
// Some forms set this key as empty, meaning no real attachment.
debug.Printf("Ignoring empty text attachment %q: %q", k, b.FormValues[k])
continue
}
textKey := k
text := b.FormValues[textKey]
nameKey := strings.Replace(k, "attached_text", "attached_file", 1)
name, ok := b.FormValues[nameKey]
if !ok {
name := strings.TrimSpace(b.FormValues[nameKey])
if name == "" {
debug.Printf("%s defined, but corresponding filename element %q is not set", textKey, nameKey)
name = "FormData.txt" // Fallback (better than nothing)
}
Expand Down

0 comments on commit 4dc5577

Please sign in to comment.