Closed antonFlego closed 9 years ago
@antonFlego Hi, thank you so much for reporting this! Is it possible that this is fixed on master: http://try.zorba.io/queries/xquery/BvQnO3QoXTobGaGviA%2BHQpDhiY0%3D ? I added to a test at #130, let's see if it passes.
@antonFlego Hi, thanks for reporting this. I am also unable to reproduce this locally with the master zorba. I also tested putting the json document in a file as you did. What version of zorba are you running?
Hi,
Sorry for the late replay (I had good long holidays :))
The version with problem was "Kratos" (3.0.0) https://github.com/28msec/zorba/releases on both Windows 8.1 and Ubuntu 14.10.
Anton
On Fri, Dec 26, 2014 at 3:05 AM, Federico Cavalieri < notifications@github.com> wrote:
@antonFlego https://github.com/antonFlego Hi, thanks for reporting this. I am also unable to reproduce this locally with the master zorba. I also tested putting the json document in a file as you did. What version of zorba are you running?
— Reply to this email directly or view it on GitHub https://github.com/28msec/zorba/issues/129#issuecomment-68136114.
Hi @antonFlego , I will try to reproduce it on 3.0.0 but I think it has been fixed in the master. Best Federico
Example of failing json:
{ "phone" : ["604 123-1234","406 321-4321"], "phoneNumbers2" : [ "212 732-1234", "646 123-4567" ] }
Script to try (if the above is in the file failing.json
import module namespace jsd="http://zorba.io/modules/json-xml"; import module namespace fls="http://expath.org/ns/file"; import module namespace jsdi="http://jsoniq.org/functions";
declare variable $jdata := fls:read-text("failing.json"); declare variable $jsnTree := jsdi:parse-json($jdata); declare variable $asXML := jsd:json-to-xml($jsnTree);
[ $asXML ]
Problem is in snelson.cpp (zorba-3.0/src/runtime/json)
The cause is that POP_ITEM(json) is executed when switching from array to an object (array bieng in an object) even when json had not been pushed previously (like for arrays).
The solution that worked for me:
What I have added is the check if the previous state was in_array and for that case the pop is skipped. Note that the added & modified lines are not done in the coding style of the rest of the code; I was aiming to make a minimalistic fix with little disruption to the existing code and its organization.
--- snelson.cpp 2014-12-23 10:30:28.165997461 -0800 +++ snelson_fix.cpp 2014-12-23 10:32:12.097996333 -0800 @@ -174,11 +174,12 @@
+ bool fa_popJSON = (IN_STATE(in_array))? false :true; POP_STATE(); POP_ITEM_ELEMENT(); if ( IN_STATE( in_object ) ) { POP_ITEM( xml );
(had to add some escape sequences for the diff to show up reasonably)
Thanks, Anton