Skip to content

Commit caed79c

Browse files
authored
Merge pull request #3045 from dolthub/elianddb/fix-9280-escape-ctrl-z-comment-strs
Fixes dolthub/dolt#9280 Update query tests for \Z escape character
2 parents 2f1daeb + 5a60e1b commit caed79c

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,16 +1033,32 @@ var AlterTableScripts = []ScriptTest{
10331033
Name: "alter table comments are escaped",
10341034
SetUpScript: []string{
10351035
"create table t (i int);",
1036-
`alter table t modify column i int comment "newline \n | return \r | backslash \\ | NUL \0 \x00"`,
1037-
`alter table t add column j int comment "newline \n | return \r | backslash \\ | NUL \0 \x00"`,
1036+
`alter table t modify column i int comment "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A"`,
1037+
`alter table t add column j int comment "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A"`,
10381038
},
10391039
Assertions: []ScriptTestAssertion{
10401040
{
10411041
Query: "show create table t",
10421042
Expected: []sql.Row{{
10431043
"t",
1044-
"CREATE TABLE `t` (\n `i` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'," +
1045-
"\n `j` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
1044+
"CREATE TABLE `t` (\n `i` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'," +
1045+
"\n `j` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'\n" +
1046+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
1047+
},
1048+
},
1049+
},
1050+
{
1051+
Name: "alter table supports non-escaped \\Z",
1052+
SetUpScript: []string{
1053+
"create table t (i int);",
1054+
`alter table t modify column i int comment "ctrlz \Z \\Z"`,
1055+
},
1056+
Assertions: []ScriptTestAssertion{
1057+
{
1058+
Query: "show create table t",
1059+
Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" +
1060+
" `i` int COMMENT 'ctrlz \x1A \\\\Z'\n" +
1061+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
10461062
},
10471063
},
10481064
},

enginetest/queries/create_table_queries.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ var CreateTableQueries = []WriteQueryTest{
5353
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT=''''"}},
5454
},
5555
{
56-
WriteQuery: `create table tableWithComment (pk int) COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00"`,
56+
WriteQuery: `create table tableWithComment (pk int) COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A"`,
5757
ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
5858
SelectQuery: "SHOW CREATE TABLE tableWithComment",
59-
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'"}},
59+
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'"}},
60+
},
61+
{
62+
WriteQuery: `create table tableWithComment (pk int) COMMENT "ctrlz \Z \x1A \\Z \\\Z"`,
63+
ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
64+
SelectQuery: "SHOW CREATE TABLE tableWithComment",
65+
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='ctrlz \x1A x1A \\\\Z \\\\\x1A'"}},
6066
},
6167
{
6268
WriteQuery: `create table tableWithColumnComment (pk int COMMENT "'")`,
@@ -71,10 +77,10 @@ var CreateTableQueries = []WriteQueryTest{
7177
ExpectedSelect: []sql.Row{{"tableWithColumnComment", "CREATE TABLE `tableWithColumnComment` (\n `pk` int COMMENT ''''\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
7278
},
7379
{
74-
WriteQuery: `create table tableWithColumnComment (pk int COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00")`,
80+
WriteQuery: `create table tableWithColumnComment (pk int COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A")`,
7581
ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
7682
SelectQuery: "SHOW CREATE TABLE tableWithColumnComment",
77-
ExpectedSelect: []sql.Row{{"tableWithColumnComment", "CREATE TABLE `tableWithColumnComment` (\n `pk` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
83+
ExpectedSelect: []sql.Row{{"tableWithColumnComment", "CREATE TABLE `tableWithColumnComment` (\n `pk` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
7884
},
7985
{
8086
WriteQuery: `create table floattypedefs (a float(10), b float(10, 2), c double(10, 2))`,

sql/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func RemoveSpaceAndDelimiter(query string, d rune) string {
133133
})
134134
}
135135

136+
// EscapeSpecialCharactersInComment escapes special characters in a comment string.
136137
func EscapeSpecialCharactersInComment(comment string) string {
137138
commentString := comment
138139
commentString = strings.ReplaceAll(commentString, "'", "''")

0 commit comments

Comments
 (0)