@@ -112,7 +112,6 @@ pub fn SizedRegex(ops: comptime_int, char_sets: comptime_int) type {
112
112
113
113
/// Match a regex pattern in `haystack`, if found, this returns a `Match`.
114
114
pub fn match (regex : * const SizedRegexT , haystack : []const u8 ) ? Match {
115
- if (haystack .len == 0 ) return null ;
116
115
const maybe_matched = regex .matchInternal (haystack );
117
116
if (maybe_matched ) | m | {
118
117
const m1 = m [0 ];
@@ -2425,3 +2424,20 @@ test "Uppercase Greek" {
2425
2424
test "M of N multibyte" {
2426
2425
try testMatchEnd ("abλ{3,5}" , "abλλλλ" );
2427
2426
}
2427
+
2428
+ test "zero length match on zero length haystack" {
2429
+ const mvzr = @import ("mvzr.zig" );
2430
+ const regex = mvzr .compile (".*" );
2431
+ const the_match = regex .? .match ("" );
2432
+ try std .testing .expect (the_match != null );
2433
+ try std .testing .expectEqual (0 , the_match .? .start );
2434
+ try std .testing .expectEqual (0 , the_match .? .end );
2435
+ }
2436
+ test "zero length optional match on zero length haystack" {
2437
+ const mvzr = @import ("mvzr.zig" );
2438
+ const regex = mvzr .compile (".?" );
2439
+ const the_match = regex .? .match ("" );
2440
+ try std .testing .expect (the_match != null );
2441
+ try std .testing .expectEqual (0 , the_match .? .start );
2442
+ try std .testing .expectEqual (0 , the_match .? .end );
2443
+ }
0 commit comments