Skip to content

Regression: isAnyCharRequiredQuoting() is broken on Windows in JsonCpp 1.9.3 for some locales. #1187

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

Closed
TheStormN opened this issue Jun 9, 2020 · 2 comments · Fixed by #1189

Comments

@TheStormN
Copy link
Contributor

TheStormN commented Jun 9, 2020

Describe the bug
The tab character is not escaped on Windows with various locales. This bug is a regression in 1.9.3, it is not present in 1.9.2.

To Reproduce
Steps to reproduce the behavior:

setlocale(LC_ALL, "English_United States.1252");

Json::Value result(Json::objectValue);
result["test"] = "\tTest123";

Json::StreamWriterBuilder builder;
assert(Json::writeString(builder, result) == "{\"test\":\"\\tTest123\"}" );

Expected behavior
The tab character should be escaped.

Desktop:

  • OS: Windows 10 1909
  • Meson version - Using Conan
  • Ninja version - Using Conan

Additional context
isAnyCharRequiredQuoting() uses std::isprint() which gives different results on Windows. The version of that function in 1.9.2 was working properly. Perhaps you can just revert it?

Update: It seems that the locale does not matter, to reproduce the bug you only need to have \t as a special character among the normal string.

Update 2: It seems that the locale does matter. Had to restart the PC to get proper results after changing the locale several times.

@TheStormN TheStormN changed the title Regression: isAnyCharRequiredQuoting() is broken on Windows with non-default locale in 1.9.3 Regression: isAnyCharRequiredQuoting() is broken on Windows in 1.9.3 Jun 9, 2020
@TheStormN TheStormN changed the title Regression: isAnyCharRequiredQuoting() is broken on Windows in 1.9.3 Regression: isAnyCharRequiredQuoting() is broken on Windows in JsonCpp 1.9.3 Jun 9, 2020
@BillyDonahue
Copy link
Contributor

Wait, are you saying std::isprint('\t') returns true on Windows?!
Let's get an answer to that specific question?

@TheStormN
Copy link
Contributor Author

TheStormN commented Jun 10, 2020

@BillyDonahue Yeah, I had hard times debugging that, but it seems that it depends on the locale. For example English_United States.1252 does return true for \t. I've updated my issue description.

So, basically it depends on the users system-wide locale if this will work or not. I've provided a easy to reproduce version with setting the locale by using C++ code.

@TheStormN TheStormN changed the title Regression: isAnyCharRequiredQuoting() is broken on Windows in JsonCpp 1.9.3 Regression: isAnyCharRequiredQuoting() is broken on Windows in JsonCpp 1.9.3 for some locales. Jun 10, 2020
BillyDonahue added a commit that referenced this issue Jun 10, 2020
`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.

Has bitten others, e.g. laurikari/tre#64

Fixes #1187
BillyDonahue added a commit that referenced this issue Jun 11, 2020
* avoid isprint

`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.

Has bitten others, e.g. laurikari/tre#64

Fixes #1187

* semicolon (rookie mistake!)
BillyDonahue added a commit that referenced this issue Jun 11, 2020
* avoid isprint

`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.

Has bitten others, e.g. laurikari/tre#64

Fixes #1187

* semicolon (rookie mistake!)

* Windows tab escape testing with custom locale (#1190)

Co-authored-by: Nikolay Baklicharov <[email protected]>
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 a pull request may close this issue.

2 participants