Skip to content

Commit 6d99f34

Browse files
committed
Improving the ability to change relative paths according to path to root
: allows url with params (file.css?param=sample)
1 parent c360c6f commit 6d99f34

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

lessc.inc.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class lessc {
5252

5353
public $importDisabled = false;
5454
public $importDir = '';
55-
55+
5656
public $allowUrlRewrite = true; // rewrite urls relative to imported files
5757

5858
protected $numberPrecision = null;
@@ -803,26 +803,30 @@ protected function rewriteUrls($url) {
803803

804804
if ($baseImportDir === $lastImportDir)
805805
return $url;
806-
806+
807+
$arguments = null;
808+
if(strpos($url,'?') !== false)
809+
list($url, $arguments) = explode('?', $url);
810+
807811
$urlPath = realpath($lastImportDir.DIRECTORY_SEPARATOR.$url);
808812
if ($urlPath === false)
809-
return $url;
813+
return $arguments ? $url.'?'.$arguments : $url;
810814

811815
$baseArray = explode(DIRECTORY_SEPARATOR, $baseImportDir);
812816
$urlArray = explode(DIRECTORY_SEPARATOR, $urlPath);
813-
817+
814818
$i = 0;
815819
foreach ($baseArray as $i => $segment) {
816820
if (!isset($baseArray[$i], $urlArray[$i]) || $baseArray[$i] !== $urlArray[$i])
817821
break;
818822
}
819-
823+
820824
$newUrl = str_repeat('../', count($baseArray) - $i);
821825
$newUrl .= implode('/', array_slice($urlArray, $i));
822-
823-
return $newUrl;
826+
827+
return $arguments ? $newUrl.'?'.$arguments : $newUrl;
824828
}
825-
829+
826830
protected function lib_isnumber($value) {
827831
return $this->toBool($value[0] == "number");
828832
}

0 commit comments

Comments
 (0)