Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't double-quote a CSV field only for having a leading space #1101

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/pkg/output/record_writer_csv_colorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"bufio"
"errors"
"strings"
"unicode"
"unicode/utf8"

"github.com/johnkerl/miller/internal/pkg/colorizer"
Expand Down Expand Up @@ -173,6 +172,8 @@ func validDelim(r rune) bool {
// fieldNeedsQuotes reports whether our field must be enclosed in quotes.
// Fields with a Comma, fields with a quote or newline, and
// fields which start with a space must be enclosed in quotes.
// [NOTE: https://www.rfc-editor.org/rfc/rfc4180 doesn't specify this so Miller
// does not use this.]
// We used to quote empty strings, but we do not anymore (as of Go 1.4).
// The two representations should be equivalent, but Postgres distinguishes
// quoted vs non-quoted empty string during database imports, and it has
Expand Down Expand Up @@ -205,6 +206,8 @@ func fieldNeedsQuotes(field string, comma rune) bool {
}
}

r1, _ := utf8.DecodeRuneInString(field)
return unicode.IsSpace(r1)
// Not used by Miller as noted above
// r1, _ := utf8.DecodeRuneInString(field)
// return unicode.IsSpace(r1)
return false
}
1 change: 1 addition & 0 deletions test/cases/io-rfc-csv/0019/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --csv cat ${CASEDIR}/input
Empty file.
2 changes: 2 additions & 0 deletions test/cases/io-rfc-csv/0019/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a,b,c
leading, space,should not be double-quoted
2 changes: 2 additions & 0 deletions test/cases/io-rfc-csv/0019/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a,b,c
leading, space,should not be double-quoted