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

Only escape compulsory characters for JSON by default (#2137) #2138

Closed
wants to merge 1 commit into from

Conversation

Burgch
Copy link
Contributor

@Burgch Burgch commented Feb 7, 2018

Fixes #2137

@obiltschnig obiltschnig added this to the Release 1.8.2 milestone Feb 7, 2018
@Burgch
Copy link
Contributor Author

Burgch commented Feb 7, 2018

Fixed a bad merge in JSONTest.cpp and squashed the commits. The first CI build could be killed.

{
if (wrap) out << '"';
out << UTF8::escape(value.begin(), value.end());
if (escapeAllUnicode) {
Copy link
Member

Choose a reason for hiding this comment

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

please fix style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -1933,7 +1933,7 @@ void JSONTest::testEscapeUnicode()
result = parser.parse(utf8Text);
object = result.extract<Object::Ptr>();
ss.str(""); object->stringify(ss);
assert (ss.str() == "{\"name\":\"g\\u00FCnter\"}");
assert (ss.str() == "{\"name\":\"g\xC3\xBCnter\"}");
Copy link
Member

Choose a reason for hiding this comment

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

I'd leave this test as is and create another one that tests functionality without escaping. This change will break the code, so there should be a way to force the parser to escape.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree - the code was broken by 1.8.0, and this is returning it back to the former functionality. This test would fail as is with versions < 1.8.0

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I did not state it correctly. This test is named testEscapeUnicode and it should do what its name implies - test (un)escaping the unicode. What was before does not matter, we should do the right thing now. And that includes allowing end user to choose whether the returned JSON string is unicode-escaped or not - probably just change in the JSON::stringifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not able to commit much more time on this; is there a small tweak to the PR that would mean you'd accept it? Perhaps renaming the test to testParsingUnicode, which is most of what it does anyway?

Copy link
Member

Choose a reason for hiding this comment

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

That would be fine, but the main concern is that a json containing unicode characters can not be escaped when stringified (that does not look like a big change, either).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't need to be escaped though - any compliant JSON parser must accept the non-escaped characters as well as the escaped ones, as this test is demonstrating.

Copy link
Member

Choose a reason for hiding this comment

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

user puts in

"{ \"name\" : \"\\u4e2d\" }"

does something with it (add or remove something), and gets out

"{\"name\":\"\xE4\xB8\xAD\"}"

now, it is true that those things are equivalent for JSON and a compliant parser must accept them both. but from my experience, people can be more picky than parsers, especially about the superficial things. I'll finish it, thanks for reporting the issue and the fixes so far.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks very much, appreciate it!

@aleks-f
Copy link
Member

aleks-f commented Feb 7, 2018

@Burgch Somehow I ended up commenting in your repo, so both those comments and the ones in pull are showing here. In any case - overall, I agree with the pull and reasoning that escaping should not be default, but since we are breaking existing functionality here, somehow JSON library should have the option to escape, too (didn't yet look into details of what would be the best way to achieve this).

@aleks-f
Copy link
Member

aleks-f commented Feb 7, 2018

moved to #2145

@aleks-f aleks-f closed this Feb 7, 2018
@Burgch Burgch deleted the json-unicode-escape branch February 12, 2018 17:55
@Burgch Burgch restored the json-unicode-escape branch March 17, 2023 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants