Skip to content
Open
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
2 changes: 1 addition & 1 deletion unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (d *Decoder) unmarshal(val reflect.Value, line string) error {
}
case len(v) >= 2 && strings.HasPrefix(v, Wrapper) && strings.HasSuffix(v, Wrapper):
// (1) .. ,"", .. (2) ..," text text ", ..
combined = append(combined, v[1:len(v)])
combined = append(combined, v[1:len(v)-1])
merged = ""
case strings.HasPrefix(v, Wrapper):
// .. ," text, more text", .. (1st part)
Expand Down
15 changes: 15 additions & 0 deletions unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const (
CsvWithHeader = `s,i,f,b
Hello,42,23.45,true`
CsvWithoutHeader = `Hello,true,42,23.45`
CsvQuoted = `"Hello",true,42,23.45`
CsvWhitespace = ` Hello , true , 42 , 23.45`
CsvSemicolon = `Hello;true;42;23.45`
CsvComment = `# Comment line
Expand Down Expand Up @@ -317,6 +318,20 @@ func TestUnmarshalWithoutHeader(t *testing.T) {
CheckA(t, a[0], A1)
}

func TestUnmarshalQuoted(t *testing.T) {
r := bytes.NewReader([]byte(CsvQuoted))
dec := NewDecoder(r).Header(false)
a := make([]*A, 0)
if err := dec.Decode(&a); err != nil {
t.Error(err)
}
if len(a) != 1 {
t.Errorf("invalid record count, got=%d expected=%d", len(a), 1)
return
}
CheckA(t, a[0], A1)
}

func TestUnmarshalRecords(t *testing.T) {
r := bytes.NewReader([]byte(CsvWithHeader))
dec := NewDecoder(r)
Expand Down