Merge lp:~paul-lucas/zorba/bug-1025622 into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Chris Hillery
Approved revision: 10954
Merged at revision: 10948
Proposed branch: lp:~paul-lucas/zorba/bug-1025622
Merge into: lp:zorba
Diff against target: 198 lines (+89/-24)
9 files modified
ChangeLog (+1/-0)
src/api/serialization/serializer.cpp (+42/-22)
src/api/serialization/serializer.h (+1/-1)
src/util/ascii_util.h (+38/-0)
test/rbkt/ExpQueryResults/zorba/jsoniq/coll_dyn_03.xml.res (+1/-1)
test/rbkt/ExpQueryResults/zorba/jsoniq/string_escapes.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/jsoniq/supplemental_plane.xml.res (+1/-0)
test/rbkt/Queries/zorba/jsoniq/string_escapes.xq (+2/-0)
test/rbkt/Queries/zorba/jsoniq/supplemental_plane.xq (+2/-0)
To merge this branch: bzr merge lp:~paul-lucas/zorba/bug-1025622
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Dennis Knochenwefel Approve
Paul J. Lucas Approve
Review via email: mp+115636@code.launchpad.net

Commit message

Now doing proper JSON serialization.

Description of the change

Now doing proper JSON serialization.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Chris Hillery (ceejatec) wrote :

Cool, thanks. Please add a couple test cases including the problem query described in the bug report; also, add a note to the Changelog mentioning the bug fix.

review: Needs Fixing
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1025622-2012-07-18T23-51-03.584Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Needs Fixing, 1 Pending.

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

I added a mention in the change log and also the one test (can't think of others).

Revision history for this message
Chris Hillery (ceejatec) wrote :

s/supplementory/supplementary/

Revision history for this message
Dennis Knochenwefel (dennis-knochenwefel) wrote :

http://json.org/ says that not only '"' and '\' need to be escaped with a backslash but also a solidus '/'.

And, some control characters have special backspace escapes: backspace (x8 -> \b), formfeed (xC -> \f), newline (xA -> \n), carriage return (xD -> \r) and HTab (x9 -> \t). Currently, they are serialized as hex.

I would propose to add tests for those as well.

review: Needs Fixing
lp:~paul-lucas/zorba/bug-1025622 updated
10952. By Paul J. Lucas

Fixed typo.

10953. By Paul J. Lucas

Now emitting \b, \f, \n, etc.

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

json.org says that '/' *MAY* be escaped, but it's not *REQUIRED* for it to be so.

As for the rest, I've added code to emit them. (The original code didn't emit them either.) Note that it wasn't wrong, just less pretty.

I added a test (within the limits of what Zorba accepts in characters).

Revision history for this message
Dennis Knochenwefel (dennis-knochenwefel) wrote :

cannot test it on windows as it doesn't currently build on windows (this doesn't have anything to do with this branch).

on linux:

The following tests FAILED:
        1104 - test/rbkt/zorba/jsoniq/coll_dyn_03 (Failed)

review: Needs Fixing
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

I think that query is wrong since there are newline literals in strings rather than \n.

lp:~paul-lucas/zorba/bug-1025622 updated
10954. By Paul J. Lucas

Fixed expected result.

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

Actually, the query may be OK, but the expected result is wrong. I've fixed it.

Revision history for this message
Dennis Knochenwefel (dennis-knochenwefel) :
review: Approve
Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1025622-2012-07-19T18-07-03.448Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-07-17 15:49:17 +0000
3+++ ChangeLog 2012-07-19 17:41:22 +0000
4@@ -32,6 +32,7 @@
5 * Streaming execution for tumbling windows (also fixes bug #1010051).
6
7 Bug Fixes/Other Changes:
8+ * Fixed bug #1025622 (Incorrect JSON serialization of supplementary plane code points)
9 * Fixed bug #1016606 (DOCTYPE in the input of the parse-fragment function)
10 * Fixed bug #1002993 (bug during revalidation after update; improper condition
11 for calling TypeOps::get_atomic_type_code() from
12
13=== modified file 'src/api/serialization/serializer.cpp'
14--- src/api/serialization/serializer.cpp 2012-07-13 06:50:40 +0000
15+++ src/api/serialization/serializer.cpp 2012-07-19 17:41:22 +0000
16@@ -31,8 +31,10 @@
17 #include "api/unmarshaller.h"
18
19 #include "util/ascii_util.h"
20+#include "util/string_util.h"
21+#include "util/unicode_util.h"
22+#include "util/utf8_string.h"
23 #include "util/utf8_util.h"
24-#include "util/string_util.h"
25 #include "util/xml_util.h"
26
27 #include "system/globalenv.h"
28@@ -1203,29 +1205,47 @@
29 /*******************************************************************************
30
31 ********************************************************************************/
32-void serializer::json_emitter::emit_json_string(zstring string)
33+void serializer::json_emitter::emit_json_string(zstring const &string)
34 {
35 tr << '"';
36- zstring::const_iterator i = string.begin();
37- zstring::const_iterator end = string.end();
38- for (; i < end; i++)
39- {
40- if (*i < 0x20)
41- {
42- // Escape control sequences
43- std::stringstream hex;
44- hex << "\\u" << std::setw(4) << std::setfill('0')
45- << std::hex << static_cast<int>(*i);
46- tr << hex.str();
47- continue;
48- }
49- if (*i == '\\' || *i == '"')
50- {
51- // Output escape char for \ or "
52- tr << '\\';
53- // Fall through to output original character
54- }
55- tr << *i;
56+ utf8_string<zstring const> const u( string );
57+ FOR_EACH( utf8_string<zstring const>, i, u ) {
58+ unicode::code_point const cp = *i;
59+ if ( ascii::is_cntrl( cp ) ) {
60+ switch ( cp ) {
61+ case '\b': tr << "\\b"; break;
62+ case '\f': tr << "\\f"; break;
63+ case '\n': tr << "\\n"; break;
64+ case '\r': tr << "\\r"; break;
65+ case '\t': tr << "\\t"; break;
66+ default: {
67+ std::ostringstream oss;
68+ oss << std::hex << std::setfill('0') << "\\u" << std::setw(4) << cp;
69+ tr << oss.str();
70+ }
71+ }
72+ continue;
73+ }
74+ if ( unicode::is_supplementary_plane( cp ) ) {
75+ unsigned high, low;
76+ unicode::convert_surrogate( cp, &high, &low );
77+ std::ostringstream oss;
78+ oss << std::hex << std::setfill('0')
79+ << "\\u" << std::setw(4) << high
80+ << "\\u" << std::setw(4) << low;
81+ tr << oss.str();
82+ continue;
83+ }
84+ switch ( cp ) {
85+ case '\\':
86+ case '"':
87+ tr << '\\';
88+ // no break;
89+ default: {
90+ utf8::encoded_char_type ec;
91+ tr.write( ec, utf8::encode( cp, ec ) );
92+ }
93+ }
94 }
95 tr << '"';
96 }
97
98=== modified file 'src/api/serialization/serializer.h'
99--- src/api/serialization/serializer.h 2012-07-13 06:50:40 +0000
100+++ src/api/serialization/serializer.h 2012-07-19 17:41:22 +0000
101@@ -402,7 +402,7 @@
102
103 void emit_jsoniq_xdm_node(store::Item *item, int depth);
104
105- void emit_json_string(zstring string);
106+ void emit_json_string(zstring const &string);
107
108 store::Item_t theJSONiqValueName;
109 store::Item_t theTypeName;
110
111=== modified file 'src/util/ascii_util.h'
112--- src/util/ascii_util.h 2012-07-12 17:29:55 +0000
113+++ src/util/ascii_util.h 2012-07-19 17:41:22 +0000
114@@ -141,6 +141,25 @@
115 }
116
117 /**
118+ * Checks whether the given character is a control character. This function
119+ * exists to make a proper function out of the standard iscntrl(3) that may be
120+ * implemented as a macro.
121+ *
122+ * @param CharType The character type.
123+ * @param c The character to check.
124+ * @return Returns \c true only if the character is a control character.
125+ */
126+template<typename CharType> inline
127+bool is_cntrl( CharType c ) {
128+#ifdef WIN32
129+ // Windows' iscntrl() implementation crashes for non-ASCII characters.
130+ return __isascii( c ) && iscntrl( c );
131+#else
132+ return iscntrl( c );
133+#endif
134+}
135+
136+/**
137 * Checks whether the given character is a decimal digit. This function exists
138 * to make a proper function out of the standard isdigit(3) that may be
139 * implemented as a macro.
140@@ -160,6 +179,25 @@
141 }
142
143 /**
144+ * Checks whether the given character is a printing character. This function
145+ * exists to make a proper function out of the standard isprint(3) that may be
146+ * implemented as a macro.
147+ *
148+ * @param CharType The character type.
149+ * @param c The character to check.
150+ * @return Returns \c true only if the character is a printing character.
151+ */
152+template<typename CharType> inline
153+bool is_print( CharType c ) {
154+#ifdef WIN32
155+ // Windows' isprint() implementation crashes for non-ASCII characters.
156+ return __isascii( c ) && isprint( c );
157+#else
158+ return isprint( c );
159+#endif
160+}
161+
162+/**
163 * Checks whether the given character is a punctuation character. This function
164 * exists to make a proper function out of the standard ispunct(3) that may be
165 * implemented as a macro.
166
167=== modified file 'test/rbkt/ExpQueryResults/zorba/jsoniq/coll_dyn_03.xml.res'
168--- test/rbkt/ExpQueryResults/zorba/jsoniq/coll_dyn_03.xml.res 2012-02-08 02:23:20 +0000
169+++ test/rbkt/ExpQueryResults/zorba/jsoniq/coll_dyn_03.xml.res 2012-07-19 17:41:22 +0000
170@@ -1,1 +1,1 @@
171-[ "\u000aXXX-01" ]{ "p1" : 1, "p2" : 2 }[ "\u000aXXX-02" ][ "\u000aXXX-03" ]{ "p1" : 3, "p2" : 4 }{ "p1" : 1, "p2" : 2 }{ "p1" : 5 }[ "\u000aXXX-04" ]{ "index" : 3 }[ "\u000aXXX-05" ][ "\u000aXXX-06" ]{ "p1" : 3, "p2" : 4 }{ "p1" : 1, "p2" : 2 }[ 1, 2, 3 ]{ "p1" : 6 }[ ]{ "p1" : 5 }[ "\u000aXXX-07" ][ "\u000aXXX-08" ][ 1 ][ "\u000aXXX-09" ]{ "p1" : 3, "p2" : 4 }[ 1, 2, 3 ]{ "p1" : 6 }[ ]{ "p1" : 5 }[ "\u000aXXX-10" ][ "\u000aXXX-11" ]{ "p1" : 3, "p2" : 4 }[ 1, 2, 3 ]{ "p1" : 6 }[ "\u000a" ]
172+[ "\nXXX-01" ]{ "p1" : 1, "p2" : 2 }[ "\nXXX-02" ][ "\nXXX-03" ]{ "p1" : 3, "p2" : 4 }{ "p1" : 1, "p2" : 2 }{ "p1" : 5 }[ "\nXXX-04" ]{ "index" : 3 }[ "\nXXX-05" ][ "\nXXX-06" ]{ "p1" : 3, "p2" : 4 }{ "p1" : 1, "p2" : 2 }[ 1, 2, 3 ]{ "p1" : 6 }[ ]{ "p1" : 5 }[ "\nXXX-07" ][ "\nXXX-08" ][ 1 ][ "\nXXX-09" ]{ "p1" : 3, "p2" : 4 }[ 1, 2, 3 ]{ "p1" : 6 }[ ]{ "p1" : 5 }[ "\nXXX-10" ][ "\nXXX-11" ]{ "p1" : 3, "p2" : 4 }[ 1, 2, 3 ]{ "p1" : 6 }[ "\n" ]
173
174=== added file 'test/rbkt/ExpQueryResults/zorba/jsoniq/string_escapes.xml.res'
175--- test/rbkt/ExpQueryResults/zorba/jsoniq/string_escapes.xml.res 1970-01-01 00:00:00 +0000
176+++ test/rbkt/ExpQueryResults/zorba/jsoniq/string_escapes.xml.res 2012-07-19 17:41:22 +0000
177@@ -0,0 +1,1 @@
178+{ "string" : "\n\r\t\\\"" }
179
180=== added file 'test/rbkt/ExpQueryResults/zorba/jsoniq/supplemental_plane.xml.res'
181--- test/rbkt/ExpQueryResults/zorba/jsoniq/supplemental_plane.xml.res 1970-01-01 00:00:00 +0000
182+++ test/rbkt/ExpQueryResults/zorba/jsoniq/supplemental_plane.xml.res 2012-07-19 17:41:22 +0000
183@@ -0,0 +1,1 @@
184+{ "string" : "\ud83d\udc4a" }
185
186=== added file 'test/rbkt/Queries/zorba/jsoniq/string_escapes.xq'
187--- test/rbkt/Queries/zorba/jsoniq/string_escapes.xq 1970-01-01 00:00:00 +0000
188+++ test/rbkt/Queries/zorba/jsoniq/string_escapes.xq 2012-07-19 17:41:22 +0000
189@@ -0,0 +1,2 @@
190+let $s := "&#10;&#13;&#9;&#92;&#34;"
191+return { "string": $s }
192
193=== added file 'test/rbkt/Queries/zorba/jsoniq/supplemental_plane.xq'
194--- test/rbkt/Queries/zorba/jsoniq/supplemental_plane.xq 1970-01-01 00:00:00 +0000
195+++ test/rbkt/Queries/zorba/jsoniq/supplemental_plane.xq 2012-07-19 17:41:22 +0000
196@@ -0,0 +1,2 @@
197+let $s := "&#128074;"
198+return { "string": $s }

Subscribers

People subscribed via source and target branches