Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
backend: fix all wrong escape of '\Z' as '\x26' (which is '&')
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Mar 16, 2020
1 parent 3c8f4d7 commit 789c94e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lightning/backend/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (enc tidbEncoder) appendSQLBytes(sb *strings.Builder, value []byte) {
sb.WriteString(`\r`)
case '\t':
sb.WriteString(`\t`)
case 0x26:
case 26:
sb.WriteString(`\Z`)
case '\'':
sb.WriteString(`''`)
Expand Down
2 changes: 1 addition & 1 deletion lightning/backend/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *mysqlSuite) TestWriteRowsReplaceOnDup(c *C) {
types.NewFloat64Datum(5e-324),
types.NewFloat64Datum(1.7976931348623157e+308),
types.NewFloat64Datum(-0.0),
types.NewStringDatum("甲乙丙\r\n\x00\x26'\"\\`"),
types.NewStringDatum("甲乙丙\r\n\x00\x1a'\"\\`"),
types.NewBinaryLiteralDatum(types.NewBinaryLiteralFromUint(0xabcdef, 6)),
types.NewMysqlBitDatum(types.NewBinaryLiteralFromUint(0x98765432, 4)),
types.NewDecimalDatum(types.NewDecFromFloatForTest(12.5)),
Expand Down
2 changes: 1 addition & 1 deletion lightning/mydump/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func unescape(
case 't':
return "\t"
case 'Z':
return "\x26"
return "\x1a"
default:
return substr[1:]
}
Expand Down
2 changes: 1 addition & 1 deletion lightning/mydump/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (s *testMydumpParserSuite) TestVariousSyntax(c *C) {
},
{
input: `('\0\b\n\r\t\Z\'\a')`,
expected: [][]types.Datum{{types.NewStringDatum("\x00\b\n\r\t\x26'a")}},
expected: [][]types.Datum{{types.NewStringDatum("\x00\b\n\r\t\x1a'a")}},
},
{
input: `(CONVERT("[1,2,3]" USING UTF8MB4))`,
Expand Down
1 change: 1 addition & 0 deletions tests/issue_282/data/issue282-schema-create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE `issue282` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
4 changes: 4 additions & 0 deletions tests/issue_282/data/issue282.t_access3-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*!40103 SET TIME_ZONE='+00:00' */;
CREATE TABLE `t_access3` (
`accessKey` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
5 changes: 5 additions & 0 deletions tests/issue_282/data/issue282.t_access3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!40103 SET TIME_ZONE='+00:00' */;
INSERT INTO `t_access3` VALUES
('@P&FLASHSHA');
INSERT INTO `t_access3` VALUES
('\Z');
25 changes: 25 additions & 0 deletions tests/issue_282/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
#
# Copyright 2020 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

for backend in tidb importer; do
run_sql 'DROP DATABASE IF EXISTS issue282;'
run_lightning --backend $backend

run_sql "SELECT hex(accessKey) FROM issue282.t_access3"
check_contains 'hex(accessKey): 405026464C415348534841'
check_contains 'hex(accessKey): 1A'
done

0 comments on commit 789c94e

Please sign in to comment.