Skip to content

Commit

Permalink
Trim whitespace from form vars in XML attachment
Browse files Browse the repository at this point in the history
I found this difference when comparing against Winlink Express's output
using the same Form template. Winlink Express trims trailing whitespace
before writing the form variables as XML.
  • Loading branch information
martinhpedersen committed Apr 13, 2024
1 parent 12def2e commit 51e115f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/forms/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (b messageBuilder) buildXML() []byte {
ReplyTemplate: filename(b.Template.ReplyTemplatePath),
}
for k, v := range b.FormValues {
// Trim leading and trailing whitespace. Winlink Express does
// this, judging from the produced XML attachments.
v = strings.TrimSpace(v)
form.Variables = append(form.Variables, Variable{xml.Name{Local: k}, v})
}
// Sort vars by name to make sure the output is deterministic.
Expand Down
4 changes: 3 additions & 1 deletion internal/forms/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestInsertionTagReplacer(t *testing.T) {
"<GridSquare>": "JO29PJ",
"<Latitude>": "59.4138",
"<Longitude>": "5.2680",
"<GPSValid>": "YES ", // This trailing space appears to be intentional,
"<GPSValid>": "YES",
"<GPSLatitude>": "59.4138",
"<GPSLongitude>": "5.2680",
}
Expand All @@ -65,6 +65,7 @@ func TestBuildXML(t *testing.T) {
FormValues: map[string]string{
"var1": "foo",
"var2": "bar",
"var3": " baz \t\n", // Leading and trailing whitespace trimmed
},
}
expect := []byte(`
Expand All @@ -82,6 +83,7 @@ func TestBuildXML(t *testing.T) {
<variables>
<var1>foo</var1>
<var2>bar</var2>
<var3>baz</var3>
</variables>
</RMS_Express_Form>
`)
Expand Down

0 comments on commit 51e115f

Please sign in to comment.