@@ -61,7 +61,7 @@ public function testFindMarkdownFileInSubfolder()
6161 $ method ->setAccessible ( true );
6262
6363 $ basePath = vfsStream::url ( 'views/testcontroller ' );
64- $ result = $ method ->invoke ( $ this ->markdown , $ basePath , 'page2 ' );
64+ $ result = $ method ->invoke ( $ this ->markdown , $ basePath , 'subfolder/ page2 ' );
6565
6666 $ this ->assertNotNull ( $ result );
6767 $ this ->assertStringContainsString ( 'subfolder ' , $ result );
@@ -75,7 +75,7 @@ public function testFindMarkdownFileInDeepNestedFolder()
7575 $ method ->setAccessible ( true );
7676
7777 $ basePath = vfsStream::url ( 'views/testcontroller ' );
78- $ result = $ method ->invoke ( $ this ->markdown , $ basePath , 'page3 ' );
78+ $ result = $ method ->invoke ( $ this ->markdown , $ basePath , 'subfolder/deep/ page3 ' );
7979
8080 $ this ->assertNotNull ( $ result );
8181 $ this ->assertStringContainsString ( 'deep ' , $ result );
@@ -107,13 +107,51 @@ public function testFindMarkdownFileReturnsNullForInvalidBasePath()
107107
108108 public function testRenderWithNestedMarkdownFile ()
109109 {
110- $ this ->markdown ->setPage ( 'page2 ' );
110+ $ this ->markdown ->setPage ( 'subfolder/ page2 ' );
111111
112112 $ result = $ this ->markdown ->render ( [] );
113113
114114 $ this ->assertStringContainsString ( '<h1>Nested Page</h1> ' , $ result );
115115 $ this ->assertStringContainsString ( '<html> ' , $ result );
116116 $ this ->assertStringContainsString ( '</html> ' , $ result );
117117 }
118+
119+ public function testFindMarkdownFileWithBackslashSeparator ()
120+ {
121+ $ reflection = new \ReflectionClass ( $ this ->markdown );
122+ $ method = $ reflection ->getMethod ( 'findMarkdownFile ' );
123+ $ method ->setAccessible ( true );
124+
125+ $ basePath = vfsStream::url ( 'views/testcontroller ' );
126+ $ result = $ method ->invoke ( $ this ->markdown , $ basePath , 'subfolder\page2 ' );
127+
128+ $ this ->assertNotNull ( $ result );
129+ $ this ->assertStringContainsString ( 'subfolder ' , $ result );
130+ $ this ->assertStringEndsWith ( 'page2.md ' , $ result );
131+ }
132+
133+ public function testFindMarkdownFileBlocksDirectoryTraversal ()
134+ {
135+ $ reflection = new \ReflectionClass ( $ this ->markdown );
136+ $ method = $ reflection ->getMethod ( 'findMarkdownFile ' );
137+ $ method ->setAccessible ( true );
138+
139+ $ basePath = vfsStream::url ( 'views/testcontroller ' );
140+ $ result = $ method ->invoke ( $ this ->markdown , $ basePath , '../page1 ' );
141+
142+ $ this ->assertNull ( $ result );
143+ }
144+
145+ public function testFindMarkdownFileBlocksComplexDirectoryTraversal ()
146+ {
147+ $ reflection = new \ReflectionClass ( $ this ->markdown );
148+ $ method = $ reflection ->getMethod ( 'findMarkdownFile ' );
149+ $ method ->setAccessible ( true );
150+
151+ $ basePath = vfsStream::url ( 'views/testcontroller ' );
152+ $ result = $ method ->invoke ( $ this ->markdown , $ basePath , 'subfolder/../../page1 ' );
153+
154+ $ this ->assertNull ( $ result );
155+ }
118156}
119157
0 commit comments