← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug_867198 into lp:zorba/data-converters-module

 

Sorin Marian Nasoi has proposed merging lp:~zorba-coders/zorba/bug_867198 into lp:zorba/data-converters-module.

Requested reviews:
  Sorin Marian Nasoi (sorin.marian.nasoi)
  Carlos Manuel Lopez (charlie-lobo)
Related bugs:
  Bug #867198 in Zorba: "JSON converter module not proccesing strings with '<'"
  https://bugs.launchpad.net/zorba/+bug/867198

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug_867198/+merge/84617

Fixed bug #867198. Also added 2 tests.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug_867198/+merge/84617
Your team Zorba Coders is subscribed to branch lp:zorba/data-converters-module.
=== modified file 'src/com/zorba-xquery/www/modules/converters/json.xq.src/jansson_wrapper.cpp'
--- src/com/zorba-xquery/www/modules/converters/json.xq.src/jansson_wrapper.cpp	2011-10-06 07:40:17 +0000
+++ src/com/zorba-xquery/www/modules/converters/json.xq.src/jansson_wrapper.cpp	2011-12-06 14:25:25 +0000
@@ -68,14 +68,16 @@
 void replace_special_chars(
      std::string &aValue)
 {
-  replace_all(aValue, "\"", "\\\"");  //quotation mark
-  replace_all(aValue, "\\", "\\\\");  //reverse solidus
-  replace_all(aValue, "/", "\\/");    //solidus
-  replace_all(aValue, "\b", "\\b" );  //backspace
-  replace_all(aValue, "\f", "\\f" );  //formfeed
-  replace_all(aValue, "\n", "\\n" );  //new line
-  replace_all(aValue, "\r", "\\r" );  //carriage return
-  replace_all(aValue, "\t", "\\t" );  //horizontal tab
+  replace_all(aValue, "\"", "\\\""  );  //quotation mark
+  replace_all(aValue, "\\", "\\\\"  );  //reverse solidus
+  replace_all(aValue, "/" , "\\/"   );  //solidus
+  replace_all(aValue, "\b", "\\b"   );  //backspace
+  replace_all(aValue, "\f", "\\f"   );  //formfeed
+  replace_all(aValue, "\n", "\\n"   );  //new line
+  replace_all(aValue, "\r", "\\r"   );  //carriage return
+  replace_all(aValue, "\t", "\\t"   );  //horizontal tab
+  replace_all(aValue, "<" , "&lt;"  );  // <
+  replace_all(aValue, ">" , "&gt;"  );  // >
 }
 
 static void parse_Json_value(
@@ -557,7 +559,7 @@
     }
     default:
     {
-      zorba::String lType, lValue;
+      std::string lType, lValue;
       if(json_is_string(aValue))
       {
         lType  = "string";
@@ -591,6 +593,7 @@
       else if(lParent.compare("object") == 0)
       {
         aSs << " " << lName << "=";
+        replace_special_chars(lValue);
         if(lType.compare("string") == 0)
           aSs << "\"" << lValue << "\"";
         else

=== added file 'test_json/ExpQueryResults/converters/jansson/parse_json_12.xml.res'
--- test_json/ExpQueryResults/converters/jansson/parse_json_12.xml.res	1970-01-01 00:00:00 +0000
+++ test_json/ExpQueryResults/converters/jansson/parse_json_12.xml.res	2011-12-06 14:25:25 +0000
@@ -0,0 +1,1 @@
+{"html": "&lt;b&gt;bold&lt;\/b&gt;"}

=== added file 'test_json/ExpQueryResults/converters/jansson/parse_json_ml_06.xml.res'
--- test_json/ExpQueryResults/converters/jansson/parse_json_ml_06.xml.res	1970-01-01 00:00:00 +0000
+++ test_json/ExpQueryResults/converters/jansson/parse_json_ml_06.xml.res	2011-12-06 14:25:25 +0000
@@ -0,0 +1,1 @@
+<html><b>bold</b></html>

=== added file 'test_json/Queries/converters/jansson/parse_json_12.xq'
--- test_json/Queries/converters/jansson/parse_json_12.xq	1970-01-01 00:00:00 +0000
+++ test_json/Queries/converters/jansson/parse_json_12.xq	2011-12-06 14:25:25 +0000
@@ -0,0 +1,4 @@
+import module namespace json="http://www.zorba-xquery.com/modules/converters/json";;
+declare variable $json-value := '{"html":"<b>bold</b>"}';
+
+json:serialize(json:parse($json-value))

=== added file 'test_json/Queries/converters/jansson/parse_json_ml_06.xq'
--- test_json/Queries/converters/jansson/parse_json_ml_06.xq	1970-01-01 00:00:00 +0000
+++ test_json/Queries/converters/jansson/parse_json_ml_06.xq	2011-12-06 14:25:25 +0000
@@ -0,0 +1,7 @@
+import module namespace json = "http://www.zorba-xquery.com/modules/converters/json";;
+import schema namespace html-options="http://www.zorba-xquery.com/modules/converters/json-options";;
+
+json:parse('["html" ,"<b>bold</b>"]',<options xmlns="http://www.zorba-xquery.com/modules/converters/json-options"; 
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+              <json-param name="mapping" value="json-ml" type="array"/>
+            </options>)


Follow ups