Skip to content

Commit e58a977

Browse files
authored
Merge pull request #99 from il-m-yamagishi/94-fix-multiple-dots
#94 fix multiple dots
2 parents 310de02 + 9c08ebe commit e58a977

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/ReferenceContext.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,16 @@ private function reduceDots($path)
115115
{
116116
$parts = explode('/', ltrim($path, '/'));
117117
$c = count($parts);
118+
$parentOffset = 1;
118119
for ($i = 0; $i < $c; $i++) {
119120
if ($parts[$i] === '.') {
120121
unset($parts[$i]);
121122
continue;
122123
}
123-
if ($i > 0 && $parts[$i] === '..' && $parts[$i-1] !== '..') {
124-
unset($parts[$i-1]);
124+
if ($i > 0 && $parts[$i] === '..' && $parts[$i - $parentOffset] !== '..') {
125+
unset($parts[$i - $parentOffset]);
125126
unset($parts[$i]);
127+
$parentOffset += 2;
126128
}
127129
}
128130
return '/'.implode('/', $parts);

tests/ReferenceContextTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ public function normalizeUriProvider()
183183
'/var/www/api/../definitions.yaml#/components/Pet',
184184
'file:///var/www/definitions.yaml#/components/Pet',
185185
],
186+
[
187+
'/var/www/api/foo/../../definitions.yaml#/components/Pet',
188+
'file:///var/www/definitions.yaml#/components/Pet',
189+
],
186190
];
187191

188192
return $data;

0 commit comments

Comments
 (0)