From 60ea6f7190782752b18ee646d06097fb666c1213 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 18 Aug 2023 15:13:00 +0100 Subject: [PATCH] Remove an optimisation which breaks relative URLs This optimisation disables relative paths when the output path is longer than the input path - but the result of that is that the generated CSS ends up pointing to URLs that are relative to the current directory instead of being relative to the generated CSS file. input: test-in/style.css ``` .foo { background-image: url("./local.png"); } ``` output: test-out/style.css ``` .foo { background-image: url("../test-in/local.png"); } ``` output: test-out/nested/path/style.css ``` .foo { background-image: url("test-in/local.png"); } ``` --- src/Parser/Helper.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Parser/Helper.php b/src/Parser/Helper.php index cbf503b0..2cd71210 100755 --- a/src/Parser/Helper.php +++ b/src/Parser/Helper.php @@ -265,11 +265,6 @@ public static function relativePath(string $file, string $ref) } } - if (count($file) < count($ref)) { - - return static::toUrl($fileUrl); - } - while ($ref) { $r = $ref[0]; @@ -430,4 +425,4 @@ public static function fetchContent(string $url, array $options = [], array $cur ] ])); } -} \ No newline at end of file +}