Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Parser wont throw on illegal selector chars #212

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
afd5b77
Update issue templates
axunonb Apr 17, 2021
1d22508
Inserted a link to merged version/v3 changes
axunonb Apr 27, 2021
11c3033
Updated README
axunonb Apr 27, 2021
d1779f9
Merge remote-tracking branch 'upstream/main' into version/v3.0
axunonb Apr 29, 2021
cb5559a
Make parser fully covered with unit tests
axunonb Apr 29, 2021
e327de5
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb Apr 29, 2021
cab97df
Updated CHANGES.md
axunonb Apr 29, 2021
e8d9c93
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb Apr 29, 2021
294f810
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb Apr 29, 2021
792c391
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 3, 2021
4f45a84
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 9, 2021
e49db1e
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 9, 2021
2c562b5
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 9, 2021
2ba8c5f
Updated .editorconfig
axunonb May 9, 2021
7c3a12e
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 25, 2021
bda63e0
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 25, 2021
ef58744
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 26, 2021
67b2119
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 27, 2021
974224b
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 27, 2021
3e6e8ae
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 27, 2021
6219b47
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 27, 2021
34f2821
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 27, 2021
6ae6516
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 29, 2021
1d7e6f3
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 29, 2021
250270b
Merge remote-tracking branch 'upstream/version/v3.0' into version/v3.0
axunonb May 30, 2021
6550a35
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 2, 2021
a457c81
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 13, 2021
d42aaa6
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 27, 2021
1e3fccc
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 27, 2021
dc58bf2
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 27, 2021
5cdd6ae
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 29, 2021
c1f65cd
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 30, 2021
309fc5a
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 30, 2021
f7d1bbb
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 31, 2021
1062b20
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 31, 2021
6462ad3
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Aug 31, 2021
7927e19
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 3, 2021
9b5bef2
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 5, 2021
58d80ef
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 7, 2021
63991b0
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 13, 2021
11e2abf
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 13, 2021
5cfb290
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 14, 2021
40566b6
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 20, 2021
52be227
Bumped version to 3.0.0-alpha.3
axunonb Sep 20, 2021
6760a2c
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Sep 20, 2021
c4a2332
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Oct 14, 2021
6a3c30a
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Oct 16, 2021
caebf10
Merge branch 'axuno:version/v3.0' into version/v3.0
axunonb Oct 16, 2021
0e83366
Fixes #211
axunonb Oct 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/SmartFormat.Tests/Core/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ public void Parser_Throws_Exceptions(string format)
Assert.Throws<ParsingErrors>(() => formatter.Test(format, args, "Error"));
}

[TestCase("{V(LU)}")] // braces are illegal
[TestCase("{V LU }")] // blanks are illegal
[TestCase("{VĀLUĒ}")] // 0x100 and 0x112 are illegal chars
public void Parser_Throws_On_Illegal_Selector_Chars(string format)
{
var parser = GetRegularParser();
try
{
parser.ParseFormat(format);
Assert.That(true, "Should throw");
}
catch (Exception e)
{
// Throws, because selector contains 2 illegal characters
Assert.That(e, Is.InstanceOf<ParsingErrors>());
Assert.That(((ParsingErrors)e).Issues.Count, Is.EqualTo(2));
}
}

[Test]
public void Parser_Exception_ErrorDescription()
{
Expand Down
4 changes: 2 additions & 2 deletions src/SmartFormat/Core/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ private void ParseSelector(ref Placeholder? currentPlaceholder, ParsingErrors pa
// Ensure the selector characters are valid:
if (!_validSelectorChars.Contains(inputChar))
parsingErrors.AddIssue(_resultFormat,
$"'0x{Convert.ToByte(inputChar):X}': " +
$"'0x{Convert.ToUInt32(inputChar):X}': " +
_parsingErrorText[ParsingError.InvalidCharactersInSelector],
_index.Current, _index.SafeAdd(_index.Current, 1));
}
Expand All @@ -636,7 +636,7 @@ private void AddLastSelector(ref Placeholder currentPlaceholder, ParsingErrors p
currentPlaceholder.AddSelector(new Selector(Settings, _inputFormat, _index.LastEnd, _index.Current,_index.Operator, _index.Selector));
else if (_index.Operator != _index.Current) // the selector only contains illegal ("trailing") operator characters
parsingErrors.AddIssue(_resultFormat,
$"'0x{Convert.ToByte(_inputFormat[_index.Operator]):X}': " +
$"'0x{Convert.ToInt32(_inputFormat[_index.Operator]):X}': " +
_parsingErrorText[ParsingError.TrailingOperatorsInSelector],
_index.Operator, _index.Current);
_index.LastEnd = _index.SafeAdd(_index.Current, 1);
Expand Down