Skip to content

Control characters are not escaped when emitUTF8 = true #1175

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 May 19, 2020 · 1 comment · Fixed by #1178
Closed

Control characters are not escaped when emitUTF8 = true #1175

TheStormN opened this issue May 19, 2020 · 1 comment · Fixed by #1178

Comments

@TheStormN
Copy link
Contributor

TheStormN commented May 19, 2020

Describe the bug
In JsonCPP 1.9.2. There is a configuration option emitUTF8 which can be used to force the library to not escape UTF-8 characters. However, when using it, the control characters are also not escaped which breaks the output json string and other software have issues parsing it. Currently to get non-escaped UTF-8 with escaped control characters, I had to downgrade to 1.8.3.

To Reproduce

Json::Value root(Json::objectValue);

root["unprintable"] = std::string{0x01, 0x02, 0x03, 0x10};

Json::StreamWriterBuilder builder;
builder.settings_["emitUTF8"] = true;
auto result_str = Json::writeString(builder, root);

Expected behavior
The result_str should be "{"unprintable":"\u0001\u0002\u0003\u0010"}" but I get the same characters as in the input string.

Desktop (please complete the following information):

  • OS: Windows 10
  • Meson - no idea, I'm using Conan
  • Ninja version - no idea, I'm using Conan

Additional context
Version 1.8.3 does not suffer from that issue.

@TheStormN
Copy link
Contributor Author

TheStormN commented May 19, 2020

Ok it seems that it was easy to fix that bug. I submitted a PR. @dota17 @BillyDonahue It would be nice if we can get a new release with that fix, so I'll be able to fetch it from Conan and get back to the latest version. :)

BillyDonahue added a commit to BillyDonahue/jsoncpp that referenced this issue May 21, 2020
BillyDonahue added a commit that referenced this issue May 21, 2020
* Escape control chars even if emitting UTF8

See #1176
Fixes #1175

* review comments

* fix test by stopping early enough to punt on utf8-input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant