diff --git a/src/Path/FileMatch/FileMatch.php b/src/Path/FileMatch/FileMatch.php index 295b6e9..5b90eae 100644 --- a/src/Path/FileMatch/FileMatch.php +++ b/src/Path/FileMatch/FileMatch.php @@ -73,13 +73,13 @@ protected function filterDynamicPathParts( array $uriPathParts ):array { $filePathParts = explode("/", $filePath); - $matchingSibling = in_array($uriPathParts, $this->siblingFilePathParts); foreach($uriPathParts as $i => $uriPathPart) { if(!isset($filePathParts[$i])) { break; } + $matchingSibling = in_array($uriPathParts, $this->siblingFilePathParts); $filePathPart = $filePathParts[$i]; // On the last iteration, don't convert if there's a sibling match. diff --git a/test/phpunit/Path/FileMatch/BasicFileMatchTest.php b/test/phpunit/Path/FileMatch/BasicFileMatchTest.php index d4270e8..15fbfbb 100644 --- a/test/phpunit/Path/FileMatch/BasicFileMatchTest.php +++ b/test/phpunit/Path/FileMatch/BasicFileMatchTest.php @@ -90,4 +90,17 @@ public function testMatches_dynamicPath_siblingMatchesIndex():void { self::assertTrue($sut->matches("/request/dynamic-example")); self::assertFalse($sut->matches("/request/secrets")); } + + public function testMatches_nestedDynamicPath_siblingMatchesIndex():void { + $sut = new BasicFileMatch( + "page/request/@share-id/@request-id.html", + "page", + [ + "page/request/@share-id/index.html", + "page/request/@share-id/secrets.html", + ] + ); + self::assertTrue($sut->matches("/request/share123/dynamic-example")); + self::assertFalse($sut->matches("/request/share123/secrets")); + } }