neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 267 forks source link

can't deserialize string ending with backslash #213

Closed vilinski closed 4 years ago

vilinski commented 4 years ago

Repro - add this to tests/Utf8Json.Tests/StringEscapeTest.cs

            str = "\"\\\"";
            JsonSerializer.Deserialize<string>(str).Is("\\");

the string, containing a single backslash can't be deserialized. The same bug is also reproducebla for other strings with a backslash at end.

RamType0 commented 4 years ago

https://github.com/neuecc/Utf8Json/blob/608cf01589cb3feb225a6e51a2324a24466fdaa6/src/Utf8Json/JsonReader.cs#L754-L791

Maybe this code is causing this bug. This code works on policy like "Find first double quote,but if it is leaded by backslash,it is not a end of string.Otherwise,it is a end of string" This policy doesn't work well in case of this.

RamType0 commented 4 years ago

https://github.com/neuecc/Utf8Json/pull/220 I made this pull request. Actually,your issue was not correct. You need "\"\\\\\"" for representing single backslash on Json. But it was useful to find another issue.Thanks!

vilinski commented 4 years ago

Cool, hope it will be merged