Fix quote with blank #1626

Merged
lunny merged 1 commits from lunny/fix_quote into master 2020-03-25 12:28:14 +00:00
2 changed files with 13 additions and 3 deletions

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
}

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 "},
}
)