Escape tab, newline, CR and backslash in report paths (closes #7) #70

Merged
clawbot merged 1 commits from issue-7-escape-tsv-paths into next 2026-10-03 15:30:38 +02:00
Collaborator

Implements #7.

What changed

  • report and trees escape their path columns: backslash, tab, newline and carriage return are written as \\, \t, \n and \r. Every other byte is written unchanged, including bytes that are not valid UTF-8. Both commands use one function, escapePath in report.go.
  • Grouping and sorting still use the stored path. The test pair is chosen so that escaping would flip its order, because a raw tab sorts before A and \t sorts after it.
  • In trees, the root directory's node now has the path /, and its children are /srv, not //srv.
  • README.md states the rule under "Report output format", and "Trees output format" points to it.

Things to know

  • Warnings are escaped in warnf, the whole message rather than just the path argument. The error text repeats the path (for example lstat /x: ...), so escaping only the argument would still split the line.
  • escapePath skips building a strings.Replacer when none of the four bytes is present. The lint config rules out a package-level replacer, and building one per row would allocate on every row.
  • #13 also edits warnf, and #30 edits the same write loops. Whichever lands second rebases.

Disclosures

  • Rule suppressed: paralleltest on TestWarnfEscapes, which swaps the process-wide os.Stderr (the same reason as the existing TestRunHelpAndVersionSucceed).
  • Judgement call: fatal error messages (sfdupes: ..., exit 1) are not escaped, only the warnings, which is the issue's scope.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/sfdupes/issues/7. **What changed** - `report` and `trees` escape their path columns: backslash, tab, newline and carriage return are written as `\\`, `\t`, `\n` and `\r`. Every other byte is written unchanged, including bytes that are not valid UTF-8. Both commands use one function, `escapePath` in `report.go`. - Grouping and sorting still use the stored path. The test pair is chosen so that escaping would flip its order, because a raw tab sorts before `A` and `\t` sorts after it. - In `trees`, the root directory's node now has the path `/`, and its children are `/srv`, not `//srv`. - `README.md` states the rule under "Report output format", and "Trees output format" points to it. **Things to know** - Warnings are escaped in `warnf`, the whole message rather than just the path argument. The error text repeats the path (for example `lstat /x: ...`), so escaping only the argument would still split the line. - `escapePath` skips building a `strings.Replacer` when none of the four bytes is present. The lint config rules out a package-level replacer, and building one per row would allocate on every row. - https://git.eeqj.de/sneak/sfdupes/issues/13 also edits `warnf`, and https://git.eeqj.de/sneak/sfdupes/issues/30 edits the same write loops. Whichever lands second rebases. **Disclosures** - Rule suppressed: `paralleltest` on `TestWarnfEscapes`, which swaps the process-wide `os.Stderr` (the same reason as the existing `TestRunHelpAndVersionSucceed`). - Judgement call: fatal error messages (`sfdupes: ...`, exit 1) are not escaped, only the warnings, which is the issue's scope. Model: opus-5-5
clawbot added the needs-review label 2026-10-03 14:17:39 +02:00
clawbot self-assigned this 2026-10-03 14:17:40 +02:00
clawbot added 1 commit 2026-10-03 14:17:40 +02:00
A path holding a tab or newline split a row of the report or trees
output. The path columns of both now write a backslash, tab, newline
and carriage return as \\, \t, \n and \r; every other byte is written
unchanged. Grouping and sorting still use the stored path. Warnings
on stderr are escaped the same way in warnf, so each stays one line.

In trees, the root directory's node now has the path "/" instead of
an empty string, and its children's paths start with a single slash.

README states the rule under "Report output format".

Model: opus-5-5
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit c887f80f57 into next 2026-10-03 15:30:38 +02:00
clawbot deleted branch issue-7-escape-tsv-paths 2026-10-03 15:30:39 +02:00
Sign in to join this conversation.