From 598697f622bfd2089671be8a0b726f2bed629ec6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 25 Mar 2020 17:21:43 +0800 Subject: [PATCH] Fix quote with blank --- schemas/quote.go | 10 +++++++--- schemas/quote_test.go | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/schemas/quote.go b/schemas/quote.go index 2a03152e..c44abe25 100644 --- a/schemas/quote.go +++ b/schemas/quote.go @@ -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 } diff --git a/schemas/quote_test.go b/schemas/quote_test.go index 7a43bd24..708b450e 100644 --- a/schemas/quote_test.go +++ b/schemas/quote_test.go @@ -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 "}, } ) -- 2.40.1