Skip to content

Commit 710eba0

Browse files
committed
(GH-98) Unit test to confirm the bug reported in GitHub issue
1 parent 86846f5 commit 710eba0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Source/HttpMultipartParser.UnitTests/SubsequenceFinderUnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,21 @@ public void SmokeTest()
1515

1616
Assert.Equal(2, SubsequenceFinder.Search(A, B, A.Length));
1717
}
18+
19+
[Fact]
20+
// This unit test demonstrates the bug in the 'Search' method when the haystack
21+
// contains a subset of the needle. Specifically, notice the '0x0D' byte in the
22+
// sample haystack followed by '0x0D, 0x0A' (which corresponds to the needle).
23+
// See: https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/98
24+
public void Haystack_contains_subset_of_needle()
25+
{
26+
var haystack = new byte[] { 0x96, 0xC7, 0x0D, 0x0D, 0x0A, 0x2D, 0x2D, 0x63, 0x65 };
27+
var needle = new byte[] { 0x0D, 0x0A };
28+
var expectedPosition = 3;
29+
30+
var result = SubsequenceFinder.Search(haystack, needle);
31+
32+
Assert.Equal(expectedPosition, result);
33+
}
1834
}
1935
}

0 commit comments

Comments
 (0)