Browse Source

[1626] do not escape forward slash in toJSON

Jelte Jansen 13 years ago
parent
commit
5a4cf2dd59
2 changed files with 4 additions and 4 deletions
  1. 4 3
      src/lib/cc/data.cc
  2. 0 1
      src/lib/cc/tests/data_unittests.cc

+ 4 - 3
src/lib/cc/data.cc

@@ -324,8 +324,7 @@ str_from_stringstream(std::istream &in, const std::string& file, const int line,
                 c = in.get();
                 ++pos;
             } else {
-                std::cout << "[XX] cur string: " << ss.str() << std::endl;
-                throwJSONError(std::string("Bad escape for: ") + (char)in.peek(), file, line, pos);
+                throwJSONError("Bad escape", file, line, pos);
             }
         }
         ss << c;
@@ -656,7 +655,9 @@ StringElement::toJSON(std::ostream& ss) const {
     for (size_t i = 0; i < str.size(); ++i) {
         c = str[i];
         // Escape characters as defined in JSON spec
-        if (strchr("\"\\/\b\f\n\r\t", c) != NULL) {
+        // Note that we do not escape forward slash; this
+        // is allowed, but not mandatory.
+        if (strchr("\"\\\b\f\n\r\t", c) != NULL) {
             ss << '\\';
         }
         ss << c;

+ 0 - 1
src/lib/cc/tests/data_unittests.cc

@@ -321,7 +321,6 @@ TEST(Element, escape) {
     // String elements.
     escapeHelper("foo\"bar", "\"foo\\\"bar\"");
     escapeHelper("foo\\bar", "\"foo\\\\bar\"");
-    escapeHelper("foo/bar", "\"foo\\/bar\"");
     escapeHelper("foo\bbar", "\"foo\\\bbar\"");
     escapeHelper("foo\fbar", "\"foo\\\fbar\"");
     escapeHelper("foo\nbar", "\"foo\\\nbar\"");