Copied the version wrong on the second output, it was from ML 6.0-2.3.

From: [email protected] 
[mailto:[email protected]] On Behalf Of Will Sawyer
Sent: Wednesday, August 14, 2013 9:44 PM
To: [email protected]
Subject: [MarkLogic Dev General] xdmp:to-json bug

I am find in the latest version of ML 6.0-3.2 xdmp:to-json is not escaping 
backslashes correctly.  Whenever there are more than one backslashes next to 
each other it fails to escape correctly.  This is causing problems because 
depending on the text it produces invalid json.

Thanks,
-Will

Testing script:

xquery version "1.0-ml";

for $i in 1 to 10
let $string := fn:string-join( for $j in 1 to $i return '\', '')
let $json := xdmp:to-json($string)
return (
  fn:concat("String", $i, ": ", $string, " Json: ", $json,  " Slashes: ", 
(fn:string-length($json) - 2 ))
                                                                                
                                                (: substring quotes :)
)

ML 6.0-3.2  Output bad escaping
String1: \ Json: "\\" Slashes: 2
String2: \\ Json: "\\\" Slashes: 3
String3: \\\ Json: "\\\\\" Slashes: 5
String4: \\\\ Json: "\\\\\\" Slashes: 6
String5: \\\\\ Json: "\\\\\\\\" Slashes: 8
String6: \\\\\\ Json: "\\\\\\\\\" Slashes: 9
String7: \\\\\\\ Json: "\\\\\\\\\\\" Slashes: 11
String8: \\\\\\\\ Json: "\\\\\\\\\\\\" Slashes: 12
String9: \\\\\\\\\ Json: "\\\\\\\\\\\\\\" Slashes: 14
String10: \\\\\\\\\\ Json: "\\\\\\\\\\\\\\\" Slashes: 15

ML 6.0-2.3 Output good escaping
String1: \ Json: "\\" Slashes: 2
String2: \\ Json: "\\\\" Slashes: 4
String3: \\\ Json: "\\\\\\" Slashes: 6
String4: \\\\ Json: "\\\\\\\\" Slashes: 8
String5: \\\\\ Json: "\\\\\\\\\\" Slashes: 10
String6: \\\\\\ Json: "\\\\\\\\\\\\" Slashes: 12
String7: \\\\\\\ Json: "\\\\\\\\\\\\\\" Slashes: 14
String8: \\\\\\\\ Json: "\\\\\\\\\\\\\\\\" Slashes: 16
String9: \\\\\\\\\ Json: "\\\\\\\\\\\\\\\\\\" Slashes: 18
String10: \\\\\\\\\\ Json: "\\\\\\\\\\\\\\\\\\\\" Slashes: 20


NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.


 NOTICE: This email message is for the sole use of the intended recipient(s) 
and may contain confidential and privileged information. Any unauthorized 
review, use, disclosure or distribution is prohibited. If you are not the 
intended recipient, please contact the sender by reply email and destroy all 
copies of the original message.

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to