Set TrimLeadingSpace when TrimSpace is on in csv parser (#6773)

This commit is contained in:
Daniel Speichert 2019-12-11 14:25:35 -05:00 committed by Daniel Nelson
parent 61fbc68279
commit 98585a1853
2 changed files with 25 additions and 0 deletions

View File

@ -45,6 +45,7 @@ func (p *Parser) compile(r *bytes.Reader) (*csv.Reader, error) {
if p.Comment != "" { if p.Comment != "" {
csvReader.Comment = []rune(p.Comment)[0] csvReader.Comment = []rune(p.Comment)[0]
} }
csvReader.TrimLeadingSpace = p.TrimSpace
return csvReader, nil return csvReader, nil
} }

View File

@ -243,6 +243,30 @@ func TestTrimSpace(t *testing.T) {
require.Equal(t, expectedFields, metrics[0].Fields()) require.Equal(t, expectedFields, metrics[0].Fields())
} }
func TestTrimSpaceDelimetedBySpace(t *testing.T) {
p := Parser{
Delimiter: " ",
HeaderRowCount: 1,
TrimSpace: true,
TimeFunc: DefaultTime,
}
testCSV := ` first second third fourth
abcdefgh 0 2 false
abcdef 3.3 4 true
f 0 2 false`
expectedFields := map[string]interface{}{
"first": "abcdef",
"second": 3.3,
"third": int64(4),
"fourth": true,
}
metrics, err := p.Parse([]byte(testCSV))
require.NoError(t, err)
require.Equal(t, expectedFields, metrics[1].Fields())
}
func TestSkipRows(t *testing.T) { func TestSkipRows(t *testing.T) {
p := Parser{ p := Parser{
HeaderRowCount: 1, HeaderRowCount: 1,