Fix unquoted plain-CSS imports (#800)

Closes #799
This commit is contained in:
Natalie Weizenbaum 2019-08-28 14:09:35 -07:00 committed by GitHub
parent fc8c987fc1
commit a89c67b563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 4 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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;