Boost C++ Libraries: Ticket #4326: Property tree json reader and writer aren't standards-compliant https://svn.boost.org/trac10/ticket/4326 <p> According to the json standard, the "/" character should be escaped to "\/". The boost property tree Json parser generates an error when such an escape sequence is encountered on input, and doesn't properly escape it on output. </p> <p> Here is a patch for the two files based on the 1.43 tree: </p> <pre class="wiki"> --- ./json_parser_read.hpp 2010-06-09 15:20:17.000000000 +0000 +++ ./json_parser_read.hpp.old 2010-06-09 15:24:43.000000000 +0000 @@ -128,7 +128,6 @@ { case Ch('\"'): c.string += Ch('\"'); break; case Ch('\\'): c.string += Ch('\\'); break; - case Ch('/'): c.string += Ch('/'); break; case Ch('0'): c.string += Ch('\0'); break; case Ch('b'): c.string += Ch('\b'); break; case Ch('f'): c.string += Ch('\f'); break; @@ -247,7 +246,7 @@ ; escape - = chset_p(detail::widen&lt;Ch&gt;("\"\\/0bfnrt").c_str())[typename Context::a_escape(self.c)] + = chset_p(detail::widen&lt;Ch&gt;("\"\\0bfnrt").c_str())[typename Context::a_escape(self.c)] | 'u' &gt;&gt; uint_parser&lt;unsigned long, 16, 4, 4&gt;()[typename Context::a_unicode(self.c)] ; --- ./json_parser_write.hpp 2010-06-09 15:15:47.000000000 +0000 +++ ./json_parser_write.hpp.old 2010-06-09 15:24:51.000000000 +0000 @@ -36,7 +36,6 @@ else if (*b == Ch('\r')) result += Ch('\\'), result += Ch('r'); else if (*b == Ch('"')) result += Ch('\\'), result += Ch('"'); else if (*b == Ch('\\')) result += Ch('\\'), result += Ch('\\'); - else if (*b == Ch('/')) result += Ch('\\'), result += Ch('/'); else { if (std::isprint(*b, loc)) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4326 Trac 1.4.3 Leon Mergen <leon@…> Wed, 09 Jun 2010 15:32:00 GMT <link>https://svn.boost.org/trac10/ticket/4326#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4326#comment:1</guid> <description> <p> I'm sorry, the patches were backwards: </p> <pre class="wiki">--- ./json_parser_write.hpp.old 2010-06-09 15:24:51.000000000 +0000 +++ ./json_parser_write.hpp 2010-06-09 15:15:47.000000000 +0000 @@ -36,6 +36,7 @@ else if (*b == Ch('\r')) result += Ch('\\'), result += Ch('r'); else if (*b == Ch('"')) result += Ch('\\'), result += Ch('"'); else if (*b == Ch('\\')) result += Ch('\\'), result += Ch('\\'); + else if (*b == Ch('/')) result += Ch('\\'), result += Ch('/'); else { if (std::isprint(*b, loc)) --- ./json_parser_read.hpp.old 2010-06-09 15:24:43.000000000 +0000 +++ ./json_parser_read.hpp 2010-06-09 15:20:17.000000000 +0000 @@ -128,6 +128,7 @@ { case Ch('\"'): c.string += Ch('\"'); break; case Ch('\\'): c.string += Ch('\\'); break; + case Ch('/'): c.string += Ch('/'); break; case Ch('0'): c.string += Ch('\0'); break; case Ch('b'): c.string += Ch('\b'); break; case Ch('f'): c.string += Ch('\f'); break; @@ -246,7 +247,7 @@ ; escape - = chset_p(detail::widen&lt;Ch&gt;("\"\\0bfnrt").c_str())[typename Context::a_escape(self.c)] + = chset_p(detail::widen&lt;Ch&gt;("\"\\/0bfnrt").c_str())[typename Context::a_escape(self.c)] | 'u' &gt;&gt; uint_parser&lt;unsigned long, 16, 4, 4&gt;()[typename Context::a_unicode(self.c)] ; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 10 Jun 2010 12:10:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4326#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4326#comment:2</guid> <description> <p> Nothing requires forward slashes to be escaped (they're not '"', '\' or control characters), but I'll adopt the part that accepts them on parsing. </p> </description> <category>Ticket</category> </item> <item> <author>Leon Mergen <leon@…></author> <pubDate>Thu, 10 Jun 2010 16:37:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4326#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4326#comment:3</guid> <description> <p> Well, when you go to <a class="ext-link" href="http://json.org/"><span class="icon">​</span>http://json.org/</a> and look at the grammar at the right, it specifically says under "char" that / should be escaped to \/. </p> </description> <category>Ticket</category> </item> <item> <author>Leon Mergen <leon@…></author> <pubDate>Thu, 10 Jun 2010 16:45:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4326#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4326#comment:4</guid> <description> <p> <a class="ext-link" href="http://www.ietf.org/rfc/rfc4627.txt"><span class="icon">​</span>http://www.ietf.org/rfc/rfc4627.txt</a> </p> <p> That standard also says that the solidus "/" should be escaped. Apparently, it is to allow embedding of JSON inside a HTML document. </p> <p> This seems to be a reasonable explanation why: <a class="ext-link" href="http://groups.google.com/group/opensocial-and-gadgets-spec/msg/f05cbf2cac48134b"><span class="icon">​</span>http://groups.google.com/group/opensocial-and-gadgets-spec/msg/f05cbf2cac48134b</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 10 Jun 2010 17:59:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4326#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4326#comment:5</guid> <description> <p> Hmm ... makes sense. </p> </description> <category>Ticket</category> </item> <item> <author>Artem Kozlov <akz328@…></author> <pubDate>Fri, 18 Jun 2010 11:05:48 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/4326#comment:6 https://svn.boost.org/trac10/ticket/4326#comment:6 <ul> <li><strong>cc</strong> <span class="trac-author">akz328@…</span> added </li> </ul> Ticket Sebastian Redl Fri, 22 Oct 2010 12:29:39 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4326#comment:7 https://svn.boost.org/trac10/ticket/4326#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in trunk and release. </p> Ticket