Skip to content

Commit

Permalink
Fixed encoding of sql strings and added a test for it
Browse files Browse the repository at this point in the history
Signed-off-by: GuptaManan100 <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed May 4, 2021
1 parent bc7e785 commit 8b0eae4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion go/sqltypes/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,12 @@ func encodeBytesSQL(val []byte, b BinWriter) {
func BufEncodeStringSQL(buf *strings.Builder, val string) {
buf.WriteByte('\'')
for _, ch := range val {
if ch > 255 {
buf.WriteRune(ch)
continue
}
if encodedChar := SQLEncodeMap[ch]; encodedChar == DontEscape {
buf.WriteByte(byte(ch))
buf.WriteRune(ch)
} else {
buf.WriteByte('\\')
buf.WriteByte(encodedChar)
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@ var (
// The last value specified is used.
input: "create table foo (f timestamp null not null , g timestamp not null null)",
output: "create table foo (\n\tf timestamp not null,\n\tg timestamp null\n)",
}, {
// Tests unicode character §
input: "create table invalid_enum_value_name (\n\there_be_enum enum('$§!') default null\n)",
}, {
input: "alter vschema create vindex hash_vdx using hash",
}, {
Expand Down

0 comments on commit 8b0eae4

Please sign in to comment.