fix: a delimiter inside a quoted field at line start splits the column - #1156
Conversation
|
Thank you. |
allStringIndex is also used by the plain-text search highlighting, where quotes have no special meaning. The delimiter path now has its own allDelimiterIndex, called from allIndex, and allStringIndex is back to what it was on master.
|
Agreed, and there is a better reason than I realised: Pushed a second commit adding |
|
Thank you for making the changes. However, regarding the corrections, I would like you to create a separate |
Oh, I'm sorry. Actually, this is fine for now. |
|
I'll go ahead and merge this for now. |
A delimiter inside a double-quoted field is correctly ignored, unless the quoted
field is the first one on the line.
al.csv:with
--column-delimiter=, --column-mode --align:Align mode makes it visible: the padding is inserted inside the quoted field,
because
"aandb"are being treated as two columns. In column mode the cursorcolumn is the truncated
"arather than the whole field.Cause
allStringIndexskips a quoted field only after it has already found adelimiter:
A quote at position 0 is never examined, so the delimiter inside the first field
is counted.
The fix
Check for a leading quote before the first search, and pull the skip into a
skipQuotedhelper so both places do the same thing.An unclosed quote keeps its current behaviour:
strings.Indexreturns -1 ands[qpos+2:]becomess[1:], so only the opening quote is skipped and the restof the line is scanned as usual. That matches what the original code did for a
mid-line unclosed quote, and keeps this change to the one bug.
Verification
Two cases in
Test_allStringIndex, one for a line that is only a quoted fieldand one for a quoted field followed by more columns.
Removing the leading-quote skip fails both:
The existing mid-line quoted cases pass under that mutation, which is what pins
the behaviour the change must not alter.
go test ./...is ok across all packages.gofumpt -lis clean on both files Itouched. No new fixture files, so the
t.TempDir()and Windows CI hazard doesnot arise.
golangci-lintreports 9 issues repo-wide andgofumpt -lflagsdraw.goandmove_updown.go, all pre-existing on master in files I did not touch.Disclosure: written with AI assistance (Claude Code). The before and after come from running binaries built from each tree in a real terminal under tmux, and I ran the mutation check myself.