Bug #87722 inconsistent json escaping when using json type
Submitted: 11 Sep 2017 5:47 Modified: 12 Sep 2017 0:42
Reporter: Adam Scarr Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:5.7.19 OS:Linux
Assigned to: CPU Architecture:Any

[11 Sep 2017 5:47] Adam Scarr
Description:
When decoding json values \u001f is sent unescaped even though every other control character is escaped. According to json spec all control characters must be escaped, so many decoders will break if they see this character.

Every other control character is escaped correctly, so I assume this is a off by one on a boundary check?

"\u0000"
"\u0001"
"\u0002"
"\u0003"
"\u0004"
"\u0005"
"\u0006"
"\u0007"
"\b"
"\t"
"\n"
"\u000b"
"\f"
"\r"
"\u000e"
"\u000f"
"\u0010"
"\u0011"
"\u0012"
"\u0013"
"\u0014"
"\u0015"
"\u0016"
"\u0017"
"\u0018"
"\u0019"
"\u001a"
"\u001b"
"\u001c"
"\u001d"
"\u001e"
""        -- what!?
" "

How to repeat:
select cast('"\\u001f"' as json);

What happens:
""

What should happen:
"\u001f"
[11 Sep 2017 7:06] MySQL Verification Team
Hello Adam,

Thank you for the report and feedback!

Thanks,
Umesh
[11 Sep 2017 7:37] Adam Scarr
I realised that the unicode control character might not render on some systems. On my machine 

select cast('"\\u001f"' as json);

Renders as a box symbol, not an empty string.
[11 Sep 2017 10:38] Knut Anders Hatlen
Hi Adam,

Thank you for your bug report. A fix for this bug was committed to the development source tree together with the fix for bug#86898.
[12 Sep 2017 0:42] Adam Scarr
Nice, Any chance of a bugfix for 5.7?
[6 Oct 2017 15:16] Jon Stephens
BUG#86898 was also fixed in MySQL 5.7.21. Updated the 5.7.21 changelog to reflect this.
[15 Jul 2018 6:18] MySQL Verification Team
Bug #91621 marked as duplicate of this one