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

json::dump() silently crashes if items contain accented letters #1365

Closed
pietro68 opened this issue Nov 20, 2018 · 4 comments
Closed

json::dump() silently crashes if items contain accented letters #1365

pietro68 opened this issue Nov 20, 2018 · 4 comments
Labels
platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@pietro68
Copy link

  • If a string field contains accented letters (e.g. à è ), a json::dump to std::string will silently crash

  • run this simple snippet:
    void foobar() { using namespace nlohmann; json foo = { "resumè" }; std::string bar = foo.dump(4); }

  • I expect the .dump operation to complete without problems...

  • ...but instead, it silently crashes (i.e. control flow goes out of scope of foobar() )

  • compiler: Visual Studio 2015 version 14.0.25431.01 update 3; Windows 10

  • Did you use a released version of the library or the version from the develop branch? yes

@nlohmann
Copy link
Owner

Can you provide more information on the crash? An exception? A stack trace?

@pietro68
Copy link
Author

Sure. Code snippet upgraded to:
{ try { json foo = { "resumè" }; std::string bar = foo.dump(4); } catch (std::exception& e) { std::cout << e.what() << std::endl; } }

And it prints out:

[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xE8

@nlohmann
Copy link
Owner

This is the description of the error: your compiler seems not to encode strings as UTF-8. Hence we have an exception, because we encountered an invalid byte. You can fix this by making your compiler use UTF-8, or add an error handler to ignore or replace these invalid bytes (see https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a50ec80b02d0f3f51130d4abb5d1cfdc5.html#a50ec80b02d0f3f51130d4abb5d1cfdc5) which will remove the exception.

@nlohmann nlohmann added platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Nov 20, 2018
@pietro68
Copy link
Author

pietro68 commented Nov 20, 2018

Thanks, that solved it ( File | Advanced Saved Options... | UTF-8 without signature ).
Apologies for not looking deeper. VisualStudio comes out of the box with codepage 1252 as the default encoding, I did not realize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants