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
Contributor

@sre-bot sre-bot 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
Copy link
Contributor Author

sre-bot commented Aug 30, 2019

/run-all-tests

Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bb7133 bb7133 added the status/can-merge Indicates a PR has been approved by a committer. label Sep 9, 2019
@sre-bot
Copy link
Contributor Author

sre-bot commented Sep 9, 2019

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

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. status/can-merge Indicates a PR has been approved by a committer. and removed status/can-merge Indicates a PR has been approved by a committer. labels Sep 9, 2019
@sre-bot
Copy link
Contributor Author

sre-bot commented Sep 9, 2019

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented Sep 9, 2019

@sre-bot merge failed.

@bb7133
Copy link
Member

bb7133 commented Sep 10, 2019

/run-common-test

@bb7133
Copy link
Member

bb7133 commented Sep 10, 2019

/run-all-tests

@zyxbest
Copy link
Contributor

zyxbest commented Sep 10, 2019

/run-common-test

@zz-jason
Copy link
Member

/merge

@sre-bot
Copy link
Contributor Author

sre-bot commented Sep 11, 2019

/run-all-tests

@sre-bot sre-bot merged commit 820206e into pingcap:release-3.0 Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/json status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants