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 #12096

Merged
merged 2 commits into from
Sep 10, 2019

Conversation

bb7133
Copy link
Member

@bb7133 bb7133 commented Sep 9, 2019

cherry-pick #11934 to release-2.1, with little conflict-resolve


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).

@bb7133 bb7133 changed the base branch from master to release-2.1 September 9, 2019 10:37
@bb7133 bb7133 added type/2.1 cherry-pick type/bugfix This PR fixes a bug. labels Sep 9, 2019
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 9, 2019
@bb7133 bb7133 closed this Sep 10, 2019
@bb7133 bb7133 reopened this Sep 10, 2019
@bb7133
Copy link
Member Author

bb7133 commented Sep 10, 2019

/run-all-tests

Copy link
Contributor

@winkyao winkyao 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

@AilinKid AilinKid 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/LGT3 The PR has already had 3 LGTM. label Sep 10, 2019
@winkyao winkyao merged commit 8758094 into pingcap:release-2.1 Sep 10, 2019
@bb7133 bb7133 deleted the bb7133/cherry-pick_11934_2.1 branch December 5, 2019 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1. status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants