diff --git a/lib/yson.js b/lib/yson.js index 105e1bae..ae78ad1c 100644 --- a/lib/yson.js +++ b/lib/yson.js @@ -76,7 +76,7 @@ yson.parseAsync = function(text, done, revive, M){ if(ctx.at instanceof Array){ ctx.at.push(ctx.at = {}); } else - if(tmp = ctx.s){ + if(u !== (tmp = ctx.s)){ ctx.at[tmp] = ctx.at = {}; } ctx.a = u; @@ -97,7 +97,7 @@ yson.parseAsync = function(text, done, revive, M){ ctx.at = ctx.up.pop(); break; case '[': - if(tmp = ctx.s){ + if(u !== (tmp = ctx.s)){ ctx.up.push(ctx.at); ctx.at[tmp] = ctx.at = []; } else @@ -125,6 +125,7 @@ yson.parseAsync = function(text, done, revive, M){ } } } + ctx.s = u; ctx.i = i; ctx.w = w; if(ctx.end){ @@ -157,8 +158,7 @@ function value(s){ } yson.stringifyAsync = function(data, done, replacer, space, ctx){ - //try{done(u, JSON.stringify(data, replacer, space))}catch(e){console.log('%%',e);done(e)}return; - //console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); + //try{done(u, JSON.stringify(data, replacer, space))}catch(e){done(e)}return; ctx = ctx || {}; ctx.text = ctx.text || ""; ctx.up = [ctx.at = {d: data}]; diff --git a/test/common.js b/test/common.js index a8e2a950..8f04b5c4 100644 --- a/test/common.js +++ b/test/common.js @@ -81,7 +81,14 @@ describe('Gun', function(){ JSON.stringifyAsync(obj, function(err, text){ JSON.parseAsync(text, function(err, data){ expect(data).to.be.eql([{x:"test",a:true,c:3,y:"yes","get":{"#":"chat"},foo:[1,null,null,'go'],blah:9}]); - done(); + + var obj = {a: [], b: [""], c: ["", 1], d: [1, ""], e: {"":[]}, "a\"b": {0: 1}, wow: {'': {cool: 1}}};obj.lol = {0: {sweet: 9}};obj.wat = {"": 'cool'};obj.oh = {phew: {}, "": {}}; + JSON.stringifyAsync(obj, function(err, text2){ + JSON.parseAsync(text2, function(err, data){ + expect(data).to.be.eql(obj); + done(); + }) + }) }) }); });