mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-18 00:45:47 +00:00
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:
parent
36d0ed7608
commit
39286923dc
5 changed files with 11 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
1
test/cases/io-rfc-csv/0019/cmd
Normal file
1
test/cases/io-rfc-csv/0019/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --csv cat ${CASEDIR}/input
|
||||
0
test/cases/io-rfc-csv/0019/experr
Normal file
0
test/cases/io-rfc-csv/0019/experr
Normal file
2
test/cases/io-rfc-csv/0019/expout
Normal file
2
test/cases/io-rfc-csv/0019/expout
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a,b,c
|
||||
leading, space,should not be double-quoted
|
||||
2
test/cases/io-rfc-csv/0019/input
Normal file
2
test/cases/io-rfc-csv/0019/input
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a,b,c
|
||||
leading, space,should not be double-quoted
|
||||
Loading…
Add table
Add a link
Reference in a new issue