Skip to content

Commit 88b41b6

Browse files
committed
Fix issues with dollar string literal parsing
Closes #453.
1 parent bcfe06e commit 88b41b6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

stmt/stmt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ parse:
220220
case c == '\'' || c == '"':
221221
b.quote = c
222222
// start of dollar quoted string literal (postgres)
223-
case b.allowDollar && c == '$':
223+
case b.allowDollar && c == '$' && (next == '$' || next == '_' || unicode.IsLetter(next)):
224224
var id string
225225
id, i, ok = readDollarAndTag(b.r, i, b.rlen)
226226
if ok {

stmt/stmt_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ func TestNextResetState(t *testing.T) {
184184
{`select 1\g '\g `, []string{`select 1`}, []string{`\g| '\g `}, "=", nil},
185185
{`select 1\g "\g `, []string{`select 1`}, []string{`\g| "\g `}, "=", nil},
186186
{"select 1\\g `\\g ", []string{`select 1`}, []string{"\\g| `\\g "}, "=", nil},
187+
{"select $$\\g$$\\g", []string{`select $$\g$$`}, []string{`\g|`}, "=", nil},
188+
{"select $1\\bind a b c\\g", []string{`select $1`}, []string{`\bind| a b c`, `\g|`}, "=", nil},
189+
{"select $1 \\bind a b c \\g", []string{`select $1 `}, []string{`\bind| a b c `, `\g|`}, "=", nil},
190+
{"select $2, $a$ foo $a$, $1 \\bind a b \\g", []string{`select $2, $a$ foo $a$, $1 `}, []string{`\bind| a b `, `\g|`}, "=", nil},
187191
}
188192
for i, test := range tests {
189193
b := New(sp(test.s, "\n"), WithAllowDollar(true), WithAllowMultilineComments(true), WithAllowCComments(true))

0 commit comments

Comments
 (0)