diff --git a/CHANGELOG.md b/CHANGELOG.md index 565c48d6..ae5181a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 1.22.11 +* Don't try to load unquoted plain-CSS indented-syntax imports. + * Fix a couple edge cases in `@extend` logic and related selector functions: * Recognize `:matches()` and similar pseudo-selectors as superselectors of diff --git a/lib/src/parse/sass.dart b/lib/src/parse/sass.dart index fe5aebbe..eb39aa26 100644 --- a/lib/src/parse/sass.dart +++ b/lib/src/parse/sass.dart @@ -9,6 +9,7 @@ import '../ast/sass.dart'; import '../interpolation_buffer.dart'; import '../logger.dart'; import '../util/character.dart'; +import '../value.dart'; import 'stylesheet.dart'; /// A parser for the indented syntax. @@ -98,9 +99,21 @@ class SassParser extends StylesheetParser { scanner.readChar(); next = scanner.peekChar(); } + var url = scanner.substring(start.position); + var span = scanner.spanFrom(start); - return DynamicImport(parseImportUrl(scanner.substring(start.position)), - scanner.spanFrom(start)); + if (isPlainImportUrl(url)) { + // Serialize [url] as a Sass string because [StaticImport] expects it to + // include quotes. + return StaticImport( + Interpolation([SassString(url).toString()], span), span); + } else { + try { + return DynamicImport(parseImportUrl(url), span); + } on FormatException catch (innerError) { + error("Invalid URL: ${innerError.message}", span); + } + } } bool scanElse(int ifIndentation) { diff --git a/lib/src/parse/stylesheet.dart b/lib/src/parse/stylesheet.dart index 0bcde8c7..e25e5ac2 100644 --- a/lib/src/parse/stylesheet.dart +++ b/lib/src/parse/stylesheet.dart @@ -1002,7 +1002,7 @@ abstract class StylesheetParser extends Parser { var urlSpan = scanner.spanFrom(start); whitespace(); var queries = tryImportQueries(); - if (_isPlainImportUrl(url) || queries != null) { + if (isPlainImportUrl(url) || queries != null) { return StaticImport( Interpolation([urlSpan.text], urlSpan), scanner.spanFrom(start), supports: queries?.item1, media: queries?.item2); @@ -1028,7 +1028,8 @@ abstract class StylesheetParser extends Parser { } /// Returns whether [url] indicates that an `@import` is a plain CSS import. - bool _isPlainImportUrl(String url) { + @protected + bool isPlainImportUrl(String url) { if (url.length < 5) return false; if (url.endsWith(".css")) return true;