Skip to content

Commit

Permalink
fix: FileMatch matches nested dynamic siblings
Browse files Browse the repository at this point in the history
closes #59
  • Loading branch information
g105b committed Oct 24, 2023
1 parent 01dac13 commit 141ac23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Path/FileMatch/FileMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions test/phpunit/Path/FileMatch/BasicFileMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

0 comments on commit 141ac23

Please sign in to comment.