Skip to content

Commit

Permalink
Merge 0d2de25 into 9a15f1a
Browse files Browse the repository at this point in the history
  • Loading branch information
arkie authored Nov 30, 2018
2 parents 9a15f1a + 0d2de25 commit 131843a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var (
escaper = strings.NewReplacer(`\`, `\\`, `'`, `\'`)
unescaper = strings.NewReplacer(`\\`, `\`, `\'`, `'`)
unescaper = strings.NewReplacer(`\\`, `\`, `\'`, `'`, `\n`, "\n", `\t`, "\t", `\r`, "\r")
)

func escape(s string) string {
Expand Down
1 change: 1 addition & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func newTextRows(c *conn, body io.ReadCloser, location *time.Location, useDBLocation bool) (*textRows, error) {
tsvReader := csv.NewReader(body)
tsvReader.Comma = '\t'
tsvReader.LazyQuotes = true

columns, err := tsvReader.Read()
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,33 @@ func TestTextRows(t *testing.T) {
assert.NoError(t, rows.Close())
assert.Empty(t, data)
}

func TestTextRowsQuoted(t *testing.T) {
buf := bytes.NewReader([]byte("text\nArray(String)\n['Quote: \"here\"']"))
rows, err := newTextRows(&conn{}, &bufReadCloser{buf}, time.Local, false)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, []string{"text"}, rows.Columns())
assert.Equal(t, []string{"Array(String)"}, rows.types)
dest := make([]driver.Value, 1)
if !assert.NoError(t, rows.Next(dest)) {
return
}
assert.Equal(t, []driver.Value{[]string{"Quote: \"here\""}}, dest)
}

func TestTextRowsNewLine(t *testing.T) {
buf := bytes.NewReader([]byte("text\nString\nHello\\nThere"))
rows, err := newTextRows(&conn{}, &bufReadCloser{buf}, time.Local, false)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, []string{"text"}, rows.Columns())
assert.Equal(t, []string{"String"}, rows.types)
dest := make([]driver.Value, 1)
if !assert.NoError(t, rows.Next(dest)) {
return
}
assert.Equal(t, []driver.Value{"Hello\nThere"}, dest)
}

0 comments on commit 131843a

Please sign in to comment.