Skip to content

Commit 9d01809

Browse files
committed
🐛 SQLparser quoting issue
Ensure that if a single quote was encountered in a string literal, the formatter would return '' to escape it. Before, it would attempt to write \', which is MySQL specifix syntax.
1 parent d1798da commit 9d01809

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

other/sqlparser/ast_format.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,22 @@ func (node *AssignmentExpr) Format(buf *TrackedBuffer) {
13731373
func (node *Literal) Format(buf *TrackedBuffer) {
13741374
switch node.Type {
13751375
case StrVal:
1376-
sqltypes.MakeTrusted(sqltypes.VarBinary, node.Bytes()).EncodeSQL(buf)
1376+
buf.WriteRune('\'')
1377+
for _, c := range node.Val {
1378+
switch c {
1379+
case '\n':
1380+
buf.WriteString("\\n")
1381+
case '\r':
1382+
buf.WriteString("\\r")
1383+
case '\032':
1384+
buf.WriteString("\\Z")
1385+
case '\'':
1386+
buf.WriteString("''")
1387+
default:
1388+
buf.WriteRune(c)
1389+
}
1390+
}
1391+
buf.WriteRune('\'')
13771392
case IntVal, FloatVal, DecimalVal, HexNum, BitNum:
13781393
buf.astPrintf(node, "%#s", node.Val)
13791394
case HexVal:

other/sqlparser/ast_format_fast.go

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)