Skip to content

Commit

Permalink
Fix control characters checks for multiline strings
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 13, 2019
1 parent bb44d90 commit 7d4857f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Tomlyn/Parsing/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ private void ReadNumberOrDate(char32? signPrefix = null, TextPosition? signPrefi
// If we have a space, followed by a digit, try to parse the following
if (CharHelper.IsWhiteSpace(_c) && CharHelper.IsDateTime(PeekChar()))
{
_textBuilder.AppendUtf32(_c); // Append the space
NextChar(); // skip the space
while (CharHelper.IsDateTime(_c))
{
_textBuilder.AppendUtf32(_c);
Expand Down Expand Up @@ -740,7 +742,7 @@ private void ReadString(TextPosition start, bool allowMultiline)
{
AddError("Invalid newline in a string", _position, _position);
}
else if (_c < 32 && (!isMultiLine || !CharHelper.IsNewLine(_c)))
else if (CharHelper.IsControlCharacter(_c) && (!isMultiLine || !CharHelper.IsNewLine(_c)))
{
AddError($"Invalid control character found {((char)_c).ToPrintableString()}", start, start);
}
Expand Down Expand Up @@ -948,7 +950,7 @@ private void ReadStringLiteral(TextPosition start, bool allowMultiline)
{
AddError("Invalid newline in a string", _position, _position);
}
else if (_c < 32 && (!isMultiLine || !CharHelper.IsNewLine(_c)))
else if (CharHelper.IsControlCharacter(_c) && (!isMultiLine || !CharHelper.IsNewLine(_c)))
{
AddError($"Invalid control character found {((char)_c).ToPrintableString()}", start, start);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Tomlyn/Text/CharHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ internal static partial class CharHelper
public static readonly Func<char32, int> OctalToDecFunc = OctalToDecimal;
public static readonly Func<char32, int> BinaryToDecFunc = BinaryToDecimal;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsControlCharacter(char32 c)
{
return c <= 0x1F || c == 0x7F;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsKeyStart(char32 c)
{
Expand Down

0 comments on commit 7d4857f

Please sign in to comment.