Skip to content

Commit 3c92615

Browse files
Add test for malformed SVG path parsing
1 parent ed8b402 commit 3c92615

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/ImageSharp.Drawing/Path.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ private static bool TryFindFlag(ref ReadOnlySpan<char> str, out bool value)
575575

576576
// https://www.w3.org/TR/SVG11/paths.html#PathDataBNF
577577
// flag: "0" | "1"
578+
// Adjacent flags are valid, so this consumes exactly one character.
578579
if (str.Length == 0 || (str[0] is not '0' and not '1'))
579580
{
580581
value = default;

tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ public void EmptyPath_ToLinearGeometry_ReturnsEmptyGeometry()
8686
Assert.False(segments.MoveNext());
8787
}
8888

89+
[Theory]
90+
[InlineData("M")]
91+
[InlineData("M 5")]
92+
[InlineData("V")]
93+
[InlineData("H")]
94+
[InlineData("C 1 2")]
95+
[InlineData("S 6 7")]
96+
[InlineData("Q 3 4 5")]
97+
[InlineData("T")]
98+
[InlineData("A 1 2 3 4 5 6")]
99+
[InlineData("~ 7 6 5")]
100+
public void TryParseSvgPath_ReturnsFalseForMalformedPathData(string svgPath)
101+
=> Assert.False(Path.TryParseSvgPath(svgPath, out _));
102+
103+
[Theory]
104+
[InlineData("M 10 10 L 1e999 20")]
105+
[InlineData("M 10 10 L NaN 20")]
106+
[InlineData("M 10 10 L Infinity 20")]
107+
[InlineData("M 10 10 h 1e999")]
108+
[InlineData("M 10 10 v 1e999")]
109+
[InlineData("M 10 10 A 25 25 0 2 0 50 50")]
110+
[InlineData("M 10 10 A 25 25 0 0 2 50 50")]
111+
[InlineData("M 10 10 L")]
112+
[InlineData("M 10 10 Q 20 20")]
113+
[InlineData("M 10 10 C 20 20 30 30")]
114+
public void TryParseSvgPath_ReturnsFalseForInvalidPathDataBoundaries(string svgPath)
115+
=> Assert.False(Path.TryParseSvgPath(svgPath, out _));
116+
89117
[Fact]
90118
public void PathCollection_EnumerableConstructor_PreservesPaths()
91119
{

0 commit comments

Comments
 (0)