facebook-csharp-sdk / simple-json

JSON library for .NET 2.0+/SL4+/WP7/WindowsStore with optional support for dynamic and DataContract
MIT License
380 stars 143 forks source link

deserialize a invalid json format(with number beginning) string unexpected #43

Open lostsnow opened 10 years ago

lostsnow commented 10 years ago

Reproduce code:

string s = "2a";
Object x = SimpleJson.DeserializeObject(s);

Expected result:

throw Invalid JSON string Exception

Actual result:

2

prabirshrestha commented 10 years ago

good catch. can u send a PR with failing unit test and fix if possible.

Seems like var s1 = "{\"a\":2a}"; and var s2 = "[2a]"; throws the json exception but not var s = "2a";.

The fix can be added to this line. https://github.com/facebook-csharp-sdk/simple-json/blob/e2528f3776b2e280c135ab92b4b4ca447f891b9c/src/SimpleJson/SimpleJson.cs#L548

If the index is less then charArray.Length means we haven't completed parsing the json string and should set obj to null and return false.

Seems like var s = "\"a\"2"; also doesn't throw json exception.