Skip to content

Commit

Permalink
fix: Not allow parse numeric values to description
Browse files Browse the repository at this point in the history
  • Loading branch information
skarllot committed Oct 6, 2024
1 parent 2e5eabc commit e22bcf8
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3172,7 +3172,7 @@ private void WriteDescriptionBlock()

#line 63 "C:\Users\skarl\source\repos\github\skarllot\EnumUtilities\gen\EnumUtilities.Generators\CodeWriters\Factory\DescriptionBlock.ttinclude"

WriteTryParse(x => x.Description, "Description", "description");
WriteTryParse(x => x.Description, "Description", "description", allowNumbers: false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@
}

<#+
WriteTryParse(x => x.Description, "Description", "description");
WriteTryParse(x => x.Description, "Description", "description", allowNumbers: false);

Check warning on line 64 in gen/EnumUtilities.Generators/CodeWriters/Factory/DescriptionBlock.ttinclude

View check run for this annotation

Codecov / codecov/patch

gen/EnumUtilities.Generators/CodeWriters/Factory/DescriptionBlock.ttinclude#L64

Added line #L64 was not covered by tests
}
#>
Original file line number Diff line number Diff line change
Expand Up @@ -668,33 +668,9 @@ private static bool TryParseDescription(ReadOnlySpan<char> description, StringCo
{
if (!description.IsEmpty)
{
char c = description[0];
if (char.IsWhiteSpace(c))
{
description = description.TrimStart();
if (description.IsEmpty)
{
goto ParseFailure;
}

c = description[0];
}

if ((c < '0' || c > '9') && c != '-' && c != '+')
{
return TryParseNonNumericDescription(description, comparisonType, throwOnFailure, out result);
}

bool success = EnumNumericParser.TryParse(description, out result);
if (success)
{
return true;
}

return TryParseNonNumericDescription(description, comparisonType, throwOnFailure, out result);
}

ParseFailure:
if (throwOnFailure)
{
ThrowHelper.ThrowInvalidEmptyParseArgument(nameof(description));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,33 +668,9 @@ private static bool TryParseDescription(ReadOnlySpan<char> description, StringCo
{
if (!description.IsEmpty)
{
char c = description[0];
if (char.IsWhiteSpace(c))
{
description = description.TrimStart();
if (description.IsEmpty)
{
goto ParseFailure;
}

c = description[0];
}

if ((c < '0' || c > '9') && c != '-' && c != '+')
{
return TryParseNonNumericDescription(description, comparisonType, throwOnFailure, out result);
}

bool success = EnumNumericParser.TryParse(description, out result);
if (success)
{
return true;
}

return TryParseNonNumericDescription(description, comparisonType, throwOnFailure, out result);
}

ParseFailure:
if (throwOnFailure)
{
ThrowHelper.ThrowInvalidEmptyParseArgument(nameof(description));
Expand Down

0 comments on commit e22bcf8

Please sign in to comment.