* Fixed: [JSON parsing error for a specific input. #236](https://github.com/clicon/clixon/issues/236)

* JSON empty list parse problems, eg `a:[]`
This commit is contained in:
Olof hagsand 2021-06-09 11:44:28 +02:00
parent 84f5762ab5
commit 7d59ec1a3a
4 changed files with 19 additions and 15 deletions

View file

@ -97,6 +97,8 @@ Developers may need to change their code
### Corrected Bugs ### Corrected Bugs
* Fixed: [JSON parsing error for a specific input. #236](https://github.com/clicon/clixon/issues/236)
* JSON empty list parse problems, eg `a:[]`
* Fixed: [restconf patch method unable to chage value to empty string #229](https://github.com/clicon/clixon/issues/229) * Fixed: [restconf patch method unable to chage value to empty string #229](https://github.com/clicon/clixon/issues/229)
* Fixed: [when condition error under augment in restconf #227](https://github.com/clicon/clixon/issues/227) * Fixed: [when condition error under augment in restconf #227](https://github.com/clicon/clixon/issues/227)
* Fixed: [Using YANG union with decimal64 and string leads to regexp match fail #226](https://github.com/clicon/clixon/issues/226) * Fixed: [Using YANG union with decimal64 and string leads to regexp match fail #226](https://github.com/clicon/clixon/issues/226)

View file

@ -209,6 +209,7 @@ json_current_new(clixon_json_yacc *jy,
static int static int
json_current_pop(clixon_json_yacc *jy) json_current_pop(clixon_json_yacc *jy)
{ {
clicon_debug(2, "%s", __FUNCTION__);
if (jy->jy_current) if (jy->jy_current)
jy->jy_current = xml_parent(jy->jy_current); jy->jy_current = xml_parent(jy->jy_current);
return 0; return 0;
@ -219,6 +220,7 @@ json_current_clone(clixon_json_yacc *jy)
{ {
cxobj *xn; cxobj *xn;
clicon_debug(2, "%s", __FUNCTION__);
if (jy->jy_current == NULL){ if (jy->jy_current == NULL){
return -1; return -1;
} }
@ -246,14 +248,6 @@ json_current_body(clixon_json_yacc *jy,
return retval; return retval;
} }
static int
json_empty_list(clixon_json_yacc *jy)
{
xml_rm(jy->jy_current);
jy->jy_current = NULL;
return 0;
}
%} %}
%% %%
@ -284,15 +278,15 @@ objlist : pair { _PARSE_DEBUG("objlist->pair");}
; ;
pair : string { json_current_new(_JY, $1);free($1);} ':' pair : string { json_current_new(_JY, $1);free($1);} ':'
value { json_current_pop(_JY);}{ _PARSE_DEBUG("pair->string : value");} value { json_current_pop(_JY);}{ _PARSE_DEBUG("pair->string : value");}
; ;
array : '[' ']' { json_empty_list(_JY); _PARSE_DEBUG("array->[]"); } array : '[' ']' { _PARSE_DEBUG("array->[]"); }
| '[' valuelist ']' { _PARSE_DEBUG("array->[ valuelist ]"); } | '[' valuelist ']' { _PARSE_DEBUG("array->[ valuelist ]"); }
; ;
valuelist : value { _PARSE_DEBUG("valuelist->value"); } valuelist : value { _PARSE_DEBUG("valuelist->value"); }
| valuelist { if (json_current_clone(_JY)< 0) _YYERROR("stack?");} | valuelist { if (json_current_clone(_JY)< 0) _YYERROR("stack?");}
',' value { _PARSE_DEBUG("valuelist->valuelist , value");} ',' value { _PARSE_DEBUG("valuelist->valuelist , value");}
; ;

View file

@ -64,8 +64,7 @@ expecteofx "$clixon_util_json" 0 '{"a":[0,1,2,3]}' "<a>0</a><a>1</a><a>2</a><a>3
# See test_restconf.sh # See test_restconf.sh
new "json parse empty list to xml" new "json parse empty list to xml"
expecteofx "$clixon_util_json" 0 '{"a":[]}' " expecteofx "$clixon_util_json" 0 '{"a":[]}' "<a/>"
" # XXX empty
new "json parse list json" # should be {"a":[0,1,2,3]} new "json parse list json" # should be {"a":[0,1,2,3]}
expecteofx "$clixon_util_json -j" 0 '{"a":[0,1,2,3]}' '{"a":"0"}{"a":"1"}{"a":"2"}{"a":"3"}' expecteofx "$clixon_util_json -j" 0 '{"a":[0,1,2,3]}' '{"a":"0"}{"a":"1"}{"a":"2"}{"a":"3"}'
@ -126,7 +125,16 @@ expecteofx "$clixon_util_json -jy $fyang" 0 "$JSON" '{"json:g2":"blues"}'
new "xml indirect identity with explicit ns to json" new "xml indirect identity with explicit ns to json"
expecteofx "$clixon_util_xml -ojvy $fyang" 0 '<g2 xmlns="urn:example:clixon" xmlns:ex="urn:example:clixon">ex:blues</g2>' '{"json:g2":"blues"}' expecteofx "$clixon_util_xml -ojvy $fyang" 0 '<g2 xmlns="urn:example:clixon" xmlns:ex="urn:example:clixon">ex:blues</g2>' '{"json:g2":"blues"}'
# XXX CDATA translation, should work bit does not # See https://github.com/clicon/clixon/issues/236
JSON='{"data": {"a": [],"b": [{"name": 17},{"name": 42},{"name": 99}]}}'
new "empty list followed by list"
expecteofx "$clixon_util_json" 0 "$JSON" "<data><a/><b><name>17</name></b><b><name>42</name></b><b><name>99</name></b></data>"
JSON='{"data": {"a": [],"b": [{"name": 17},{"name": []},{"name": 99}]}}'
new "empty list followed by list again empty"
expecteofx "$clixon_util_json" 0 "$JSON" "<data><a/><b><name>17</name></b><b><name/></b><b><name>99</name></b></data>"
# XXX CDATA translation, should work but does not
if false; then if false; then
JSON='{"json:c": {"s": "<![CDATA[ z > x & x < y ]]>"}}' JSON='{"json:c": {"s": "<![CDATA[ z > x & x < y ]]>"}}'
new "json parse cdata xml" new "json parse cdata xml"

View file

@ -314,7 +314,7 @@ function testrun()
# See test_json.sh # See test_json.sh
new "restconf empty list" new "restconf empty list"
expectpart "$(curl $CURLOPTS -X POST -H "Accept: application/yang-data+json" -H "Content-Type: application/yang-data+json" -d '{"clixon-example:table":{"parameter":[]}}' $proto://$addr/restconf/data)" 0 "HTTP/$HVER 201" "Location: $proto://$addr/restconf/data/clixon-example:table" expectpart "$(curl $CURLOPTS -X POST -H "Accept: application/yang-data+json" -H "Content-Type: application/yang-data+json" -d '{"clixon-example:table":[]}' $proto://$addr/restconf/data)" 0 "HTTP/$HVER 201" "Location: $proto://$addr/restconf/data/clixon-example:table"
new "restconf Re-add subtree eth/0/0 which should give error" new "restconf Re-add subtree eth/0/0 which should give error"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"ietf-interfaces:interfaces":{"interface":{"name":"eth/0/0","type":"clixon-example:eth","enabled":true}}}' $proto://$addr/restconf/data)" 0 '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"data-exists","error-severity":"error","error-message":"Data already exists; cannot create new resource"}}}' expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"ietf-interfaces:interfaces":{"interface":{"name":"eth/0/0","type":"clixon-example:eth","enabled":true}}}' $proto://$addr/restconf/data)" 0 '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"data-exists","error-severity":"error","error-message":"Data already exists; cannot create new resource"}}}'