Skip to content

Commit

Permalink
Fix invalid unicode scalar value
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 3, 2019
1 parent 04959e1 commit 6d14fef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/SharpToml/Parsing/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ private bool TryReadEscapeChar(ref TextPosition end)
case 'u':
case 'U':
{
var start = _position;
end = _position;
var maxCount = _c == 'u' ? 4 : 8;
NextChar();
Expand All @@ -837,6 +838,10 @@ private bool TryReadEscapeChar(ref TextPosition end)

if (i == maxCount)
{
if (!CharHelper.IsValidUnicodeScalarValue(value))
{
AddError($"Invalid Unicode scalar value [{value:X}]",start, start);
}
_textBuilder.AppendUtf32((char32)value);
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/SharpToml/Text/CharHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public static bool IsIdentifierContinue(char32 c)
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

public static bool IsValidUnicodeScalarValue(char32 c)
{
return c >= 0 && c <= 0xD7FF || c >= 0xE000 && c < 0x10FFFF;
}

public static bool IsDigit(char32 c)
{
return (c >= '0' && c <= '9');
Expand Down

0 comments on commit 6d14fef

Please sign in to comment.