mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 13:51:31 +01:00
Fix root-relative @import URLs as passed to importers (#1371)
Closes #1137
This commit is contained in:
parent
5a9dd9161b
commit
629881212c
@ -6,6 +6,10 @@
|
||||
relying on this bug, but if so they can simply add `!global` to the variable
|
||||
declaration to preserve the old behavior.
|
||||
|
||||
* **Potentially breaking bug fix:** Fix a bug where imports of root-relative
|
||||
URLs (those that begin with `/`) in `@import` rules would be passed to
|
||||
both Dart and JS importers as `file:` URLs.
|
||||
|
||||
## 1.35.1
|
||||
|
||||
* Fix a bug where the quiet dependency flag didn't silence warnings in some
|
||||
|
@ -1120,7 +1120,9 @@ abstract class StylesheetParser extends Parser {
|
||||
String parseImportUrl(String url) {
|
||||
// Backwards-compatibility for implementations that allow absolute Windows
|
||||
// paths in imports.
|
||||
if (p.windows.isAbsolute(url)) return p.windows.toUri(url).toString();
|
||||
if (p.windows.isAbsolute(url) && !p.url.isRootRelative(url)) {
|
||||
return p.windows.toUri(url).toString();
|
||||
}
|
||||
|
||||
// Throw a [FormatException] if [url] is invalid.
|
||||
Uri.parse(url);
|
||||
|
@ -93,6 +93,27 @@ void main() {
|
||||
'''));
|
||||
});
|
||||
|
||||
group("the imported URL", () {
|
||||
// Regression test for #1137.
|
||||
test("isn't changed if it's root-relative", () {
|
||||
compileString('@import "/orange";', importers: [
|
||||
TestImporter(expectAsync1((url) {
|
||||
expect(url, equals(Uri.parse("/orange")));
|
||||
return Uri.parse("u:$url");
|
||||
}), (url) => ImporterResult('', syntax: Syntax.scss))
|
||||
]);
|
||||
});
|
||||
|
||||
test("is converted to a file: URL if it's an absolute Windows path", () {
|
||||
compileString('@import "C:/orange";', importers: [
|
||||
TestImporter(expectAsync1((url) {
|
||||
expect(url, equals(Uri.parse("file:///C:/orange")));
|
||||
return Uri.parse("u:$url");
|
||||
}), (url) => ImporterResult('', syntax: Syntax.scss))
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
test("uses an importer's source map URL", () {
|
||||
late SingleMapping map;
|
||||
compileString('@import "orange";',
|
||||
|
@ -364,6 +364,25 @@ void main() {
|
||||
}))));
|
||||
expect(result.stats.includedFiles, equals(['foo']));
|
||||
});
|
||||
|
||||
// Regression test for #1137.
|
||||
test("isn't changed if it's root-relative", () {
|
||||
renderSync(RenderOptions(
|
||||
data: "@import '/foo'",
|
||||
importer: allowInterop(expectAsync2((url, _) {
|
||||
expect(url, equals('/foo'));
|
||||
return NodeImporterResult(contents: '');
|
||||
}))));
|
||||
});
|
||||
|
||||
test("is converted to a file: URL if it's an absolute Windows path", () {
|
||||
renderSync(RenderOptions(
|
||||
data: "@import 'C:/foo'",
|
||||
importer: allowInterop(expectAsync2((url, _) {
|
||||
expect(url, equals('file:///C:/foo'));
|
||||
return NodeImporterResult(contents: '');
|
||||
}))));
|
||||
});
|
||||
});
|
||||
|
||||
group("the previous URL", () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user