Skip to content

Commit

Permalink
fix zio/csvio.preprocess.parseField panic on empty quoted field (#3128)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwt authored Sep 29, 2021
1 parent df490e3 commit fe1cb75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion zio/csvio/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (p *preprocess) parseField() ([]byte, error) {
ending := []byte{c}
if hasstr {
// If field had quotes wrap entire field in quotes.
if last := len(p.scratch) - 1; p.scratch[last] == '\r' {
if last := len(p.scratch) - 1; last > 0 && p.scratch[last] == '\r' {
ending = []byte("\r\n")
p.scratch = p.scratch[:last]
}
Expand Down
6 changes: 6 additions & 0 deletions zio/csvio/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import (

func TestPreprocess(t *testing.T) {
const input = `
,,
"","",""
"""","""",""""
field1,"field"2,field"3" my friend
field4,"field"5 with "multiple" quotes "to" escape,field6
""",""",""" has a couple "" embedded quotes and a , comma",""" """
x,"hello,
"" world , " foo,y`
const expected = `
,,
"","",""
"""","""",""""
field1,"field2","field3 my friend"
field4,"field5 with multiple quotes to escape",field6
""",""",""" has a couple "" embedded quotes and a , comma",""" """
Expand Down

0 comments on commit fe1cb75

Please sign in to comment.