Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fix-style: php-cs-fixer.phar
cli:
docker-compose run --rm php bash

install:
install: composer.json package.json
$(DOCKER_PHP) composer install --prefer-dist --no-interaction --no-progress --ansi
$(DOCKER_NODE) yarn install

Expand Down
14 changes: 11 additions & 3 deletions src/ReferenceContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,18 @@ private function reduceDots($path)
unset($parts[$i]);
continue;
}
if ($i > 0 && $parts[$i] === '..' && $parts[$i - $parentOffset] !== '..') {
unset($parts[$i - $parentOffset]);

if ($i > 0 && $parts[$i] === '..') {
$parent = $i - $parentOffset;
//Make sure parent exists, if not, check the next parent etc
while($parent >= 0 && empty($parts[$parent])){
$parent--;
}
//Confirm parent is valid
if(!empty($parts[$parent]) && $parts[$parent] !== '..'){
unset($parts[$parent]);
}
unset($parts[$i]);
$parentOffset += 2;
}
}
return '/'.implode('/', $parts);
Expand Down
16 changes: 16 additions & 0 deletions tests/ReferenceContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ public function normalizeUriProvider()
'/var/www/api/../definitions.yaml',
'file:///var/www/definitions.yaml',
],
[
'/./definitions.yaml',
'file:///definitions.yaml',
],
[
'/var/www/api/schema/../../definitions.yaml',
'file:///var/www/definitions.yaml',
],
[
'/var/www/api/schema/./../data/./../definitions.yaml',
'file:///var/www/api/definitions.yaml',
],
[
'/var/www/api/schema/./../definitions.yaml',
'file:///var/www/api/definitions.yaml',
],
[
'/var/www/api/../definitions.yaml#/components/Pet',
'file:///var/www/definitions.yaml#/components/Pet',
Expand Down
Loading