From 4fd0472f2e7cbd12d7892cafe262199fbc1d145c Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 9 Aug 2021 16:47:45 -0700 Subject: [PATCH] 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 --- CHANGELOG.md | 5 +++++ lib/src/importer/node/implementation.dart | 2 +- pubspec.yaml | 2 +- test/node_api/importer_test.dart | 10 ++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 863a1bcd..9e5571ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/src/importer/node/implementation.dart b/lib/src/importer/node/implementation.dart index 47c0b202..fec91600 100644 --- a/lib/src/importer/node/implementation.dart +++ b/lib/src/importer/node/implementation.dart @@ -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) ?? diff --git a/pubspec.yaml b/pubspec.yaml index e82435cf..7653ca23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/node_api/importer_test.dart b/test/node_api/importer_test.dart index 03c14ac0..50f5787f 100644 --- a/test/node_api/importer_test.dart +++ b/test/node_api/importer_test.dart @@ -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", () {