Fix quote with blank #1626

Merged
lunny merged 1 commits from lunny/fix_quote into master 2 years ago
  1. 10
      schemas/quote.go
  2. 6
      schemas/quote_test.go

10
schemas/quote.go

@ -107,16 +107,17 @@ func findStart(value string, start int) int { @@ -107,16 +107,17 @@ func findStart(value string, start int) int {
return start
}
var k int
var k = -1
for j := start; j < len(value); j++ {
if value[j] != ' ' {
k = j
break
}
}
if k-1 == len(value) {
if k == -1 {
return len(value)
}
if (value[k] == 'A' || value[k] == 'a') && (value[k+1] == 'S' || value[k+1] == 's') {
k = k + 2
}
@ -178,8 +179,11 @@ func (q Quoter) QuoteTo(buf *strings.Builder, value string) error { @@ -178,8 +179,11 @@ func (q Quoter) QuoteTo(buf *strings.Builder, value string) error {
return err
}
}
var nextEnd = findWord(value, start)
if start == len(value) {
return nil
}
var nextEnd = findWord(value, start)
if err := q.quoteWordTo(buf, value[start:nextEnd]); err != nil {
return err
}

6
schemas/quote_test.go

@ -32,6 +32,12 @@ func TestAlwaysQuoteTo(t *testing.T) { @@ -32,6 +32,12 @@ func TestAlwaysQuoteTo(t *testing.T) {
{`["myschema].[mytable"]`, `"myschema.mytable"`},
{"[message_user] AS [sender]", "`message_user` AS `sender`"},
{"[myschema].[mytable] AS [table]", "myschema.mytable AS table"},
{" [mytable]", " mytable"},
{" [mytable]", " mytable"},
{"[mytable] ", "mytable "},
{"[mytable] ", "mytable "},
{" [mytable] ", " mytable "},
{" [mytable] ", " mytable "},
}
)

Loading…
Cancel
Save