Skip to content

Preserve trailing whitespace in StringToString formatting - #522

Merged
tomasaschan merged 1 commit into
spf13:masterfrom
r4venrudy:fix/string-map-trailing-whitespace
Oct 19, 2026
Merged

tomasaschan merged 1 commit into
spf13:masterfrom
r4venrudy:fix/string-map-trailing-whitespace

Conversation

@r4venrudy

@r4venrudy r4venrudy commented Oct 17, 2026 •

Copy link
Copy Markdown

StringToString formats its map with a CSV writer, then applies strings.TrimSpace to the result. That removes data from an unquoted final value: a default or explicitly set key=value is displayed as [key=value], and a whitespace-only value is displayed as empty. This also affects the default representation captured when a flag is registered.

Remove only the single newline appended by the CSV writer, matching the existing writeAsCSV helper. Keep spaces, tabs and Unicode whitespace that belong to the value.

Add eight table-driven cases, each exercised with a default map and an explicitly set value. They cover trailing spaces, tabs, a nonbreaking space, a whitespace-only value, ordinary/empty values, and CSV-quoted comma/newline controls. The four unquoted whitespace cases fail in both modes before the fix; all pass afterward.

Validation on Windows with Go 1.27.2 and Clang 23.1.3:

  • Full go test -race -count=1 ./...: passed.
  • go vet ./...: passed.
  • golangci-lint 2.14.0 with the repository configuration: zero issues on a clean LF checkout of the published commit. The initial Windows CRLF checkout produced formatter-only failures in unchanged files; no unrelated formatting changes are included.
  • gofmt and git diff --check: passed.

The change uses strings.TrimSuffix, already used by the repository and available under its Go 1.12 baseline. No new dependency or parsing behavior is introduced.

@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tomasaschan
tomasaschan merged commit c2d0368 into spf13:master Oct 19, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants