Menu

#18 Support strings containing Null characters

Unstable (example)
closed-fixed
nobody
None
5
2015-03-06
2013-04-05
No

This is a patch for the bug "Incorrect parsing of strings with null characters (\u0000) - ID: 3525583".
It basically includes the length of a string in Json::Value as part of the union, and in value and writer either the the pair (char*, length) or the c++ string are used.
It also modifies the writer to write \0 as \u0000.

The end result is that you can parse strings like "NUL: \u0000 end" which will return:
* Json::Value::asString() returns "NUL: \0 end" (stringn actually containing a \0 character
* Is written (writer.write or toStyledString) escaping the \u0000 character.

We're using this for JSONs containing blobs of binary data and it seems to work fine.
Please let me know where it'd best to add some tests for it - I'd more than happy to take a closer look at that.

The patch is done against 0.6.0-rc2 (r191).

Let me know what you think - Hopefully you can include this in the code :)

Discussion

  • Stefan Wehner

    Stefan Wehner - 2013-04-05
     
  • Mike Gelfand

    Mike Gelfand - 2014-01-25

    Great patch, Stefan. One issue though, you have lost reverse solidus escaping, so additional condition should be added to isCharacterToEscape to make it look like
    static bool isCharacterToEscape(char ch)
    {
    return ( ch >= 0 && ch <= 0x1F ) || ( ch == '\"' ) || ( ch == '\' );
    }
    There also were some changes (using r275 now) which prevent clean patch application, but nothing one couldn't deal with.

     
  • Christopher Dunn

    As of versions 1.5.0 and 0.9.0, UTF-8 with nulls is now supported at: https://github.com/open-source-parsers/jsoncpp

    Please let us know if you see a problem. We were not able to accept the patch because we had to maintain binary-compatibility. Nice work though.

     
  • Christopher Dunn

    • status: open --> closed-fixed
    • Group: --> Unstable (example)
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.