33
44namespace LordSimal \CustomHtmlElements \Test \TagEngine ;
55
6+ use LordSimal \CustomHtmlElements \Error \RegexException ;
67use LordSimal \CustomHtmlElements \TagEngine ;
78use PHPUnit \Framework \TestCase ;
89
@@ -22,6 +23,7 @@ public function testGetInstance(): void
2223 'tag_directories ' => [
2324 dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'Tags ' . DIRECTORY_SEPARATOR ,
2425 dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'plugins ' . DIRECTORY_SEPARATOR ,
26+ dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'Tags ' . DIRECTORY_SEPARATOR ,
2527 ],
2628 ];
2729 $ instance = TagEngine::getInstance ($ options );
@@ -30,4 +32,32 @@ public function testGetInstance(): void
3032 $ sameInstance = TagEngine::getInstance ();
3133 $ this ->assertSame ($ instance , $ sameInstance );
3234 }
35+
36+ public function testThrowsRegexException (): void
37+ {
38+ $ options = [
39+ 'tag_directories ' => [
40+ dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'Tags ' . DIRECTORY_SEPARATOR ,
41+ dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'plugins ' . DIRECTORY_SEPARATOR ,
42+ ],
43+ ];
44+ $ instance = TagEngine::getInstance ($ options );
45+
46+ $ test = '' ;
47+ $ pcreLimit = 100000 ;
48+ for ($ i = 0 ; $ i < $ pcreLimit ; $ i ++) {
49+ $ test .= '<c-tag>Test ' ;
50+ }
51+ for ($ i = 0 ; $ i < $ pcreLimit ; $ i ++) {
52+ $ test .= '</c-tag> ' ;
53+ }
54+
55+ try {
56+ $ instance ->parse ($ test );
57+ } catch (RegexException $ e ) {
58+ $ this ->assertEquals ('Backtrack limit was exhausted ' , $ e ->getMessage ());
59+ $ this ->assertNotEmpty ($ e ->getRegex ());
60+ $ this ->assertNotEmpty ($ e ->getSource ());
61+ }
62+ }
3363}
0 commit comments