Browse Source

Fix quote with blank (#1626)

Fix quote with blank

Reviewed-on: #1626
pull/1631/head
Lunny Xiao 3 months ago
parent
commit
34f5bc3465
2 changed files with 13 additions and 3 deletions
  1. +7
    -3
      schemas/quote.go
  2. +6
    -0
      schemas/quote_test.go

+ 7
- 3
schemas/quote.go View File

@ -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 {
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
- 0
schemas/quote_test.go View File

@ -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