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

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

* unit-test case
This commit is contained in:
John Kerl 2022-10-03 22:40:16 -04:00 committed by GitHub
parent 36d0ed7608
commit 39286923dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 3 deletions

View file

@ -45,7 +45,6 @@ import (
"bufio"
"errors"
"strings"
"unicode"
"unicode/utf8"
"github.com/johnkerl/miller/internal/pkg/colorizer"
@ -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
@ -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
}

View file

@ -0,0 +1 @@
mlr --csv cat ${CASEDIR}/input

View file

View file

@ -0,0 +1,2 @@
a,b,c
leading, space,should not be double-quoted

View file

@ -0,0 +1,2 @@
a,b,c
leading, space,should not be double-quoted