handle empty string keyed objects

This commit is contained in:
Mark Nadal 2021-06-08 16:38:03 -07:00
parent fd5e6185ac
commit af5da577cd
2 changed files with 12 additions and 5 deletions

View File

@ -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}];

View File

@ -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();
})
})
})
});
});