Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to force custom URL schemes to file paths in the Node API #1434

Merged
merged 2 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Don't crash when a Windows path is returned by a custom Node importer at the
same time as file contents.

* Don't crash when an error occurs in a stylesheet loaded via a custom importer
with a custom URL scheme.

## 1.37.5

Expand Down
12 changes: 11 additions & 1 deletion lib/src/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,20 @@ RenderResult _renderSync(RenderOptions options) {
/// Converts an exception to a [JsError].
JsError _wrapException(Object exception) {
if (exception is SassException) {
String file;
var url = exception.span.sourceUrl;
if (url == null) {
file = 'stdin';
} else if (url.scheme == 'file') {
file = p.fromUri(url);
} else {
file = url.toString();
}

return _newRenderError(exception.toString().replaceFirst("Error: ", ""),
line: exception.span.start.line + 1,
column: exception.span.start.column + 1,
file: exception.span.sourceUrl.andThen(p.fromUri) ?? 'stdin',
file: file,
status: 1);
} else {
return JsError(exception.toString());
Expand Down
18 changes: 18 additions & 0 deletions test/node_api/importer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,24 @@ void main() {
" ╵\n"
" stdin 1:9 root stylesheet"));
});

test("it occurs in a file with a custom URL scheme", () {
var error =
renderSyncError(RenderOptions(
data: "@import 'foo:bar'",
importer: allowInterop(expectAsync2((String _, void __) {
return NodeImporterResult(contents: '@error "oh no";');
}))));

expect(error,
toStringAndMessageEqual("\"oh no\"\n"
" ╷\n"
"1 │ @error \"oh no\";\n"
" │ ^^^^^^^^^^^^^^\n"
" ╵\n"
" foo:bar 1:1 @import\n"
" stdin 1:9 root stylesheet"));
});
});

group("render()", () {
Expand Down