paulbartrum / jurassic

A .NET library to parse and execute JavaScript code.
MIT License
873 stars 122 forks source link

Built-in JSON.parse doesn't like keys that start with "0"? #147

Closed Tinister closed 5 years ago

Tinister commented 5 years ago
var engine = new Jurassic.ScriptEngine();
engine.Evaluate(@"function f() { var o = JSON.parse('{""01"":""Foo"",""id"":""Foo""}'); return JSON.stringify(o); }");
Console.WriteLine(engine.CallGlobalFunction("f"));

returns {"id":"Foo"} (skips "01" key)

Keys that are numbers that don't start with 0 ("11") or alphanumeric keys that start with 0 ("0S") seem to work.

I understand that JSON properties such as "01" can be a code smell (i.e. o[1] won't work), but with this particular script it is enforcing padded strings for the hash lookups.

paulbartrum commented 5 years ago

I get {"01":"Foo","id":"Foo"} when I run your code. What version of Jurassic are you using?

Tinister commented 5 years ago

2.2.2 running on framework 4.7.2

paulbartrum commented 5 years ago

Likely this issue was fixed after that release. I'll look into doing a v2.2.3/v3.0 release ASAP.

paulbartrum commented 5 years ago

I just published a Nuget package for v3.0, can you try it and let me know if it solves your problem?

Tinister commented 5 years ago

Works great. Thanks for the extremely prompt turnaround.