zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #19822
[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba
Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.
Commit message:
Now catching (more) invalid JsonML.
Requested reviews:
Paul J. Lucas (paul-lucas)
Related bugs:
Bug #1031951 in Zorba: "json-parse segfault"
https://bugs.launchpad.net/zorba/+bug/1031951
For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/156453
Now catching (more) invalid JsonML.
--
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/156453
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/json/jsonml_array.cpp'
--- src/runtime/json/jsonml_array.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/json/jsonml_array.cpp 2013-04-02 02:49:31 +0000
@@ -62,6 +62,41 @@
namespace jsonml_array {
+// JsonML grammar
+// Source: http://www.ibm.com/developerworks/library/x-jsonml/#N10138
+//
+// element
+// = '[' tag-name ',' attributes ',' element-list ']'
+// | '[' tag-name ',' attributes ']'
+// | '[' tag-name ',' element-list ']'
+// | '[' tag-name ']'
+// | json-string
+// ;
+// tag-name
+// = json-string
+// ;
+// attributes
+// = '{' attribute-list '}'
+// | '{' '}'
+// ;
+// attribute-list
+// = attribute ',' attribute-list
+// | attribute
+// ;
+// attribute
+// = attribute-name ':' attribute-value
+// ;
+// attribute-name
+// = json-string
+// ;
+// attribute-value
+// = json-string
+// ;
+// element-list
+// = element ',' element-list
+// | element
+// ;
+
void parse( json::parser &p, store::Item_t *result ) {
ZORBA_ASSERT( result );
@@ -83,11 +118,21 @@
switch ( token.get_type() ) {
case '[':
+ if ( expect_what )
+ throw XQUERY_EXCEPTION(
+ zerr::ZJPE0006_UNEXPECTED_TOKEN,
+ ERROR_PARAMS( token )
+ );
PUSH_STATE( in_array );
expect_what = expect::element_name;
break;
case '{':
+ if ( expect_what )
+ throw XQUERY_EXCEPTION(
+ zerr::ZJPE0006_UNEXPECTED_TOKEN,
+ ERROR_PARAMS( token )
+ );
if ( state_stack.empty() )
throw XQUERY_EXCEPTION(
zerr::ZJPE0010_JSONML_ARRAY_REQUIRES_BRACKET
=== added file 'test/rbkt/Queries/zorba/json/json-jsonml_array-parse-08.spec'
--- test/rbkt/Queries/zorba/json/json-jsonml_array-parse-08.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/json/json-jsonml_array-parse-08.spec 2013-04-02 02:49:31 +0000
@@ -0,0 +1,1 @@
+Error: http://www.zorba-xquery.com/errors:ZJPE0006
=== added file 'test/rbkt/Queries/zorba/json/json-jsonml_array-parse-08.xq'
--- test/rbkt/Queries/zorba/json/json-jsonml_array-parse-08.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/json/json-jsonml_array-parse-08.xq 2013-04-02 02:49:31 +0000
@@ -0,0 +1,11 @@
+import module namespace json =
+ "http://www.zorba-xquery.com/modules/converters/json";
+
+let $opt :=
+ <options xmlns="http://www.zorba-xquery.com/modules/converters/json-options">
+ <json-format value="JsonML-array"/>
+ </options>
+let $json := '[ { "x" : "x" } ]'
+return json:parse( $json, $opt )
+
+(: vim:set et sw=2 ts=2: :)
Follow ups