Opened 13 years ago
Closed 13 years ago
#3827 closed Bugs (fixed)
Embeded null written as \0 rather than \u0000 in property_tree::write_json
Reported by: | Owned by: | Sebastian Redl | |
---|---|---|---|
Milestone: | Boost 1.42.0 | Component: | property_tree |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | Cc: |
Description
Here's an example
#include "boost/property_tree/json_parser.hpp" #include "boost/array.hpp" int main() { boost::property_tree::ptree pt; // Some random data to encode boost::array<unsigned char, 8> data = { 3,0,'W','A',0,'M',255,'z' }; pt.put("binary", std::string(data.begin(), data.end() ) ); boost::property_tree::write_json(std::cout, pt ); }
This produces the output
{ "binary": "\u0003\0WA\0M\uFFFFz" }
but from the description of JSON strings at http://www.json.org/ and the more detailed version at http://www.ietf.org/rfc/rfc4627.txt it would appear that the correct encoding of the 0 character is \u00000 rather than \0 ( which is correctly handled for other non-prinatable characters. )
Change History (2)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [59738]) Turns out JSON doesn't allow \0 as an escape sequence. Also, don't rely on is_print for figuring out which characters to escape, but instead follow the spec. Fixes bug 3827.
Note:
See TracTickets
for help on using tickets.
The fix is pretty easy, heres a patch from svn diff