Fix a crash in the Node importer

When a path was returned at the same time as a file's contents, it was
interpreted as a URL without first being translated to one. This
crashed for absolute Windows paths.

Closes #1410
This commit is contained in:
Natalie Weizenbaum 2021-08-09 16:47:45 -07:00
parent c07f46175b
commit 4fd0472f2e
4 changed files with 17 additions and 2 deletions

View File

@ -1,3 +1,8 @@
## 1.37.6
* Don't crash when a Windows path is returned by a custom Node importer at the
same time as file contents.
## 1.37.5
* No user-visible changes.

View File

@ -186,7 +186,7 @@ class NodeImporter {
if (file == null) {
return Tuple2(contents ?? '', url);
} else if (contents != null) {
return Tuple2(contents, file);
return Tuple2(contents, p.toUri(file).toString());
} else {
var resolved =
loadRelative(p.toUri(file).toString(), previous, forImport) ??

View File

@ -1,5 +1,5 @@
name: sass
version: 1.37.5
version: 1.37.6-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

View File

@ -141,6 +141,16 @@ void main() {
}))));
expect(result.stats.includedFiles, equals(['bar']));
});
// Regression test for sass/dart-sass#1410.
test("passes through an absolute file path", () {
var result = sass.renderSync(RenderOptions(
data: "@import 'foo'",
importer: allowInterop(expectAsync2((void _, void __) {
return NodeImporterResult(contents: '', file: p.absolute('bar'));
}))));
expect(result.stats.includedFiles, equals([p.absolute('bar')]));
});
});
group("with a file redirect", () {