Skip to content

Commit

Permalink
Allow tab character in normal and literal string.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndtoan96 committed Dec 21, 2022
1 parent 1691ab6 commit ee0df99
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
13 changes: 4 additions & 9 deletions src/Tomlyn.Tests/ValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,13 @@ public void TestTableArrayAndInvalidTable()
}

[Test]
public void TestValidControlCharacters()
public void TestAllowTab()
{
var input = "";
input += "backspace='\b'\n";
input += "tab='\t'\n";
input += "form_feed='\f'\n";
input += "quote='\"'\n";
input += "backslash='\\'\n";
input += "heart='\u2665'\n";
input += "some_unicode='\U0002B695'\n";
input += "tab_normal=\"\t\"\n";
input += "tab_literal='\t'\n";
var doc = Toml.Parse(input);
Assert.False(doc.HasErrors, "The document should not have errors on valid control characters");
Assert.False(doc.HasErrors, "The document should not have errors on tab character");
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/Tomlyn/Parsing/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ private void ReadString(TextPosition start, bool allowMultiline)
{
AddError("Invalid newline in a string", _position, _position);
}
else if (CharHelper.IsControlCharacter(_c) && (!isMultiLine || !CharHelper.IsWhiteSpaceOrNewLine(_c)))
else if (CharHelper.IsControlCharacter(_c) && _c != '\t' && (!isMultiLine || !CharHelper.IsWhiteSpaceOrNewLine(_c)))
{
AddError($"Invalid control character found {((char)_c).ToPrintableString()}", start, start);
}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ private void ReadStringLiteral(TextPosition start, bool allowMultiline)
{
AddError("Invalid newline in a string", _position, _position);
}
else if (CharHelper.IsControlCharacter(_c) && !CharHelper.IsNonNewlineValidControlCharacter(_c) && (!isMultiLine || !CharHelper.IsNewLine(_c)))
else if (CharHelper.IsControlCharacter(_c) && _c != '\t' && (!isMultiLine || !CharHelper.IsNewLine(_c)))
{
AddError($"Invalid control character found {((char)_c).ToPrintableString()}", start, start);
}
Expand Down
5 changes: 0 additions & 5 deletions src/Tomlyn/Text/CharHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public static bool IsControlCharacter(char32 c)
return c <= 0x1F || c == 0x7F;
}

public static bool IsNonNewlineValidControlCharacter(char32 c)
{
return c == '\b' || c == '\t' || c == '\f';
}

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

0 comments on commit ee0df99

Please sign in to comment.