Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types/json: fix an over-quoted bug in `BinaryJSON.Unquote` function (#11934) #11955

Merged
merged 6 commits into from Sep 11, 2019

Conversation

@sre-bot
Copy link

commented Aug 30, 2019

cherry-pick #11934 to release-3.0


What problem does this PR solve?

This PR tries to fix the following issue:

create table a(a json);
insert into a values ("{\"low_keywords\":\"[{\\\"x\\\":\\\"{\\\\\\\"y\\\\\\\":12}\\\"}]\"}");

In current TiDB(master/3.0/2.1):

tidb> select a->>"$.low_keywords" from a;
+----------------------+
| a->>"$.low_keywords" |
+----------------------+
| [{"x":"{"y":12}"}] |
+----------------------+
1 rows in set (0.02 sec)

In MySQL 5.7/8.0:

tidb> select a->>"$.low_keywords" from a;
+----------------------+
| a->>"$.low_keywords" |
+----------------------+
| [{"x":"{\"y\":12}"}] |
+----------------------+
1 rows in set (0.02 sec)

What is changed and how it works?

The issue is caused by the over-unquote behaviors of BinaryJSON.Unquote: for a string literal of JSON, it should be unquoted only when enclosed by double quotes(")

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
tidb> select json_unquote("\"[{\\\"x\\\":\\\"{\\\\\\\"y\\\\\\\":12}\\\"}]\"");
+------------------------------------------------------------------+
| json_unquote("\"[{\\\"x\\\":\\\"{\\\\\\\"y\\\\\\\":12}\\\"}]\"") |
+------------------------------------------------------------------+
| [{"x":"{\"y\":12}"}]                                             |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

tidb> select json_unquote("\\\\");
+----------------------+
| json_unquote("\\\\") |
+----------------------+
| \\                   |
+----------------------+
1 row in set (0.00 sec)
  • No code

Code changes

  • Has exported function/method change

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch

Release note

Fix an over-quoted bug for JSON_UNQUOTE function: only values enclosed by the double quote marks(") should be unquoted. For example, result of SELECT JSON_UNQUOTE("\\\\") should be \\(not changed).

@sre-bot

This comment has been minimized.

Copy link
Author

commented Aug 30, 2019

/run-all-tests

Copy link
Member

left a comment

LGTM

Copy link
Contributor

left a comment

LGTM

@sre-bot

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

Sorry @bb7133, you don't have permission to trigger auto merge event on this branch.

@sre-bot

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

/run-all-tests

@sre-bot

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

@sre-bot merge failed.

@bb7133

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2019

/run-common-test

@bb7133

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2019

/run-all-tests

@qrr1995

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2019

/run-common-test

@zz-jason

This comment has been minimized.

Copy link
Member

commented Sep 11, 2019

/merge

@sre-bot

This comment has been minimized.

Copy link
Author

commented Sep 11, 2019

/run-all-tests

@sre-bot sre-bot merged commit 820206e into pingcap:release-3.0 Sep 11, 2019
13 checks passed
13 checks passed
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/build_check_race Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev_2 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/common-test job succeeded
Details
idc-jenkins-ci-tidb/integration-common-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-compatibility-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-ddl-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/mybatis-test job succeeded
Details
idc-jenkins-ci-tidb/sqllogic-test-1 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/sqllogic-test-2 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/unit-test Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.