Don't parse CSV comments (#1859)

* `mlr sort -b` feature

* mlr regtest -p test/cases/cli-help && make dev

* Don't parse CSV comments

* Add tests for PR 1346

* Add tests for PR 1787

* Add test CSV files
This commit is contained in:
John Kerl 2025-08-13 17:07:32 -05:00 committed by GitHub
parent 369156b70d
commit 06e16ea3ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 62 additions and 37 deletions

View file

@ -311,15 +311,28 @@ func (r *Reader) readRecord(dst []string) ([]string, error) {
var errRead error
for errRead == nil {
line, errRead = r.readLine()
if r.Comment != 0 && nextRune(line) == r.Comment {
line = nil
continue // Skip comment lines
}
// MILLER-SPECIFIC UPDATE: DO NOT DO THIS
// if r.Comment != 0 && nextRune(line) == r.Comment {
// line = nil
// continue // Skip comment lines
// }
// MILLER-SPECIFIC UPDATE: DO NOT DO THIS
// if errRead == nil && len(line) == lengthNL(line) {
// line = nil
// continue // Skip empty lines
// line = nil
// continue // Skip empty lines
// }
// MILLER-SPECIFIC UPDATE: If the line starts with the comment character,
// don't attempt to CSV-parse it -- just hand it back as a single field.
// This allows two things:
// * User comments get passed through as intended, without being reformatted;
// * Users can do things like `# a"b` in their comments without getting an
// imbalanced-double-quote error.
if r.Comment != 0 && nextRune(line) == r.Comment {
return []string{string(line)}, nil
}
break
}
if errRead == io.EOF {