diff --git a/unmarshal.go b/unmarshal.go index 10f7a8f..23fd949 100644 --- a/unmarshal.go +++ b/unmarshal.go @@ -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) diff --git a/unmarshal_test.go b/unmarshal_test.go index 197001d..7919f4a 100644 --- a/unmarshal_test.go +++ b/unmarshal_test.go @@ -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 @@ -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)