Skip to content

Commit 56e08b0

Browse files
committed
Merge pull request #17 from SenseException/relative-path-fix
Remove ../ from relative path when already in base path's root
2 parents 472a7c7 + 77f161d commit 56e08b0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Path.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@ public static function makeRelative($path, $basePath)
676676
// relative, consider it to be relative to the given absolute path
677677
// already
678678
if ('' === $root && '' !== $baseRoot) {
679+
// If base path is already in its root
680+
if ('' === $relativeBasePath) {
681+
$relativePath = ltrim($relativePath, './\\');
682+
}
683+
679684
return $relativePath;
680685
}
681686

tests/PathTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,39 @@ public function provideMakeRelativeTests()
823823
array('phar://C:/webmozart/css/style.css', 'phar://C:/webmozart/puli', '../css/style.css'),
824824
array('phar://C:/css/style.css', 'phar://C:/webmozart/puli', '../../css/style.css'),
825825

826+
// already relative + already in root basepath
827+
array('../style.css', '/', 'style.css'),
828+
array('./style.css', '/', 'style.css'),
829+
array('../../style.css', '/', 'style.css'),
830+
array('..\\style.css', 'C:\\', 'style.css'),
831+
array('.\\style.css', 'C:\\', 'style.css'),
832+
array('..\\..\\style.css', 'C:\\', 'style.css'),
833+
array('../style.css', 'C:/', 'style.css'),
834+
array('./style.css', 'C:/', 'style.css'),
835+
array('../../style.css', 'C:/', 'style.css'),
836+
array('..\\style.css', '\\', 'style.css'),
837+
array('.\\style.css', '\\', 'style.css'),
838+
array('..\\..\\style.css', '\\', 'style.css'),
839+
array('../style.css', 'phar:///', 'style.css'),
840+
array('./style.css', 'phar:///', 'style.css'),
841+
array('../../style.css', 'phar:///', 'style.css'),
842+
array('..\\style.css', 'phar://C:\\', 'style.css'),
843+
array('.\\style.css', 'phar://C:\\', 'style.css'),
844+
array('..\\..\\style.css', 'phar://C:\\', 'style.css'),
845+
846+
array('css/../style.css', '/', 'style.css'),
847+
array('css/./style.css', '/', 'css/style.css'),
848+
array('css\\..\\style.css', 'C:\\', 'style.css'),
849+
array('css\\.\\style.css', 'C:\\', 'css/style.css'),
850+
array('css/../style.css', 'C:/', 'style.css'),
851+
array('css/./style.css', 'C:/', 'css/style.css'),
852+
array('css\\..\\style.css', '\\', 'style.css'),
853+
array('css\\.\\style.css', '\\', 'css/style.css'),
854+
array('css/../style.css', 'phar:///', 'style.css'),
855+
array('css/./style.css', 'phar:///', 'css/style.css'),
856+
array('css\\..\\style.css', 'phar://C:\\', 'style.css'),
857+
array('css\\.\\style.css', 'phar://C:\\', 'css/style.css'),
858+
826859
// already relative
827860
array('css/style.css', '/webmozart/puli', 'css/style.css'),
828861
array('css\\style.css', '\\webmozart\\puli', 'css/style.css'),

0 commit comments

Comments
 (0)