Skip to content

Commit

Permalink
Enhanced logic to skip escaped characters neuecc#63, neuecc#121
Browse files Browse the repository at this point in the history
  • Loading branch information
bristarstudio committed Mar 16, 2020
1 parent 608cf01 commit 50abb9b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Utf8Json/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,18 +767,19 @@ public ArraySegment<byte> ReadStringSegmentRaw()

for (int i = offset; i < bytes.Length; i++)
{
if (bytes[i] == (char)'\"')
if (bytes[i] == (char)'\\')
{
// is escape?
if (bytes[i - 1] == (char)'\\')
i++; // skip escaped chars
if (bytes[i] == (char)'u') // unicode escape
{
continue;
}
else
{
offset = i + 1;
goto OK;
i += 4;
}
continue;
}
if (bytes[i] == (char)'\"')
{
offset = i + 1;
goto OK;
}
}
throw CreateParsingExceptionMessage("not found end string.");
Expand Down Expand Up @@ -996,18 +997,19 @@ void ReadNextCore(JsonToken token)
offset += 1; // position is "\"";
for (int i = offset; i < bytes.Length; i++)
{
if (bytes[i] == (char)'\"')
if (bytes[i] == (char)'\\')
{
// is escape?
if (bytes[i - 1] == (char)'\\')
i++; // skip escaped chars
if (bytes[i] == (char)'u') // unicode escape
{
continue;
}
else
{
offset = i + 1;
return; // end
i+=4;
}
continue;
}
if (bytes[i] == (char)'\"')
{
offset = i + 1;
return; // end
}
}
throw CreateParsingExceptionMessage("not found end string.");
Expand Down

0 comments on commit 50abb9b

Please sign in to comment.