Skip to content

Commit 590eb82

Browse files
jkobusnorberttech
authored andcommitted
matcher fails when trying to use empty string as a pattern (#119)
1 parent 01ec0db commit 590eb82

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: src/Parser.php

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function parse(string $pattern) : Pattern\TypePattern
4646

4747
public function getAST(string $pattern) : AST\Pattern
4848
{
49+
if($pattern === '') {
50+
return new AST\Pattern(new AST\Type(''));
51+
}
52+
4953
$this->lexer->setInput($pattern);
5054
return $this->getPattern();
5155
}

Diff for: tests/MatcherTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,32 @@ public static function nullExamples()
422422
],
423423
];
424424
}
425+
426+
public static function emptyPatternString()
427+
{
428+
return [
429+
[
430+
'', '', true,
431+
'123', '', false,
432+
' ', '', false,
433+
null, '', false,
434+
1, '', false,
435+
0, '', false,
436+
'{"name": "123"}', '{"name": ""}', false,
437+
'{"name": ""}', '{"name": ""}', true,
438+
],
439+
];
440+
}
441+
442+
/**
443+
* @dataProvider emptyPatternString
444+
*/
445+
public function test_empty_pattern_in_the_json($value, $pattern, $expectedResult)
446+
{
447+
$factory = new SimpleFactory();
448+
$matcher = $factory->createMatcher();
449+
450+
$match = $matcher->match($value, $pattern);
451+
$this->assertSame($expectedResult, $match);
452+
}
425453
}

0 commit comments

Comments
 (0)