Forbid empty custom properties (#343)

This commit is contained in:
Natalie Weizenbaum 2018-05-31 20:39:33 -04:00 committed by GitHub
parent c26903e30e
commit 224dc91792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 6 deletions

View File

@ -3,6 +3,9 @@
* Fix a bug where an absolute Windows path would be considered an `input:output`
pair.
* Forbid custom properties that have no values, like `--foo:;`, since they're
forbidden by the CSS spec.
## 1.5.0
* Fix a bug where an importer would be passed an incorrectly-resolved URL when

View File

@ -205,8 +205,10 @@ abstract class Parser {
/// Consumes tokens until it reaches a top-level `":"`, `")"`, `"]"`,
/// or `"}"` and returns their contents as a string.
///
/// If [allowEmpty] is `false` (the default), this requires at least one token.
@protected
String declarationValue() {
String declarationValue({bool allowEmpty: false}) {
// NOTE: this logic is largely duplicated in
// StylesheetParser._interpolatedDeclarationValue. Most changes here should
// be mirrored there.
@ -301,6 +303,7 @@ abstract class Parser {
}
if (brackets.isNotEmpty) scanner.expectChar(brackets.last);
if (!allowEmpty && buffer.isEmpty) scanner.error("Expected token.");
return buffer.toString();
}

View File

@ -282,7 +282,7 @@ class SelectorParser extends Parser {
if (_selectorPseudoElements.contains(unvendored)) {
selector = _selectorList();
} else {
argument = declarationValue();
argument = declarationValue(allowEmpty: true);
}
} else if (_selectorPseudoClasses.contains(unvendored)) {
selector = _selectorList();
@ -297,7 +297,7 @@ class SelectorParser extends Parser {
selector = _selectorList();
}
} else {
argument = declarationValue().trimRight();
argument = declarationValue(allowEmpty: true).trimRight();
}
scanner.expectChar($rparen);

View File

@ -2119,7 +2119,8 @@ abstract class StylesheetParser extends Parser {
return null;
}
buffer.addInterpolation(_interpolatedDeclarationValue().text);
buffer
.addInterpolation(_interpolatedDeclarationValue(allowEmpty: true).text);
scanner.expectChar($rparen);
buffer.writeCharCode($rparen);
@ -2331,8 +2332,10 @@ abstract class StylesheetParser extends Parser {
/// Consumes tokens until it reaches a top-level `":"`, `")"`, `"]"`,
/// or `"}"` and returns their contents as a string.
///
/// If [allowEmpty] is `false` (the default), this requires at least one token.
///
/// Unlike [declarationValue], this allows interpolation.
StringExpression _interpolatedDeclarationValue() {
StringExpression _interpolatedDeclarationValue({bool allowEmpty: false}) {
// NOTE: this logic is largely duplicated in Parser.declarationValue. Most
// changes here should be mirrored there.
@ -2449,6 +2452,7 @@ abstract class StylesheetParser extends Parser {
}
if (brackets.isNotEmpty) scanner.expectChar(brackets.last);
if (!allowEmpty && buffer.isEmpty) scanner.error("Expected token.");
return new StringExpression(buffer.interpolation(scanner.spanFrom(start)));
}

View File

@ -515,6 +515,9 @@ class _EvaluateVisitor
(!cssValue.value.isBlank || _isEmptyList(cssValue.value))) {
_parent.addChild(new CssDeclaration(name, cssValue, node.span,
valueSpanForMap: _expressionSpan(node.value)));
} else if (name.value.startsWith('--')) {
throw _exception(
"Custom property values may not be empty.", node.value.span);
}
if (node.children != null) {

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/synchronize.dart for details.
//
// Checksum: ff6c50c58c86529e7fed4247a7381649cec1900c
// Checksum: bb333ed7c02c663af1977b3eb6c666b7bed92c1a
import 'async_evaluate.dart' show EvaluateResult;
export 'async_evaluate.dart' show EvaluateResult;
@ -518,6 +518,9 @@ class _EvaluateVisitor
(!cssValue.value.isBlank || _isEmptyList(cssValue.value))) {
_parent.addChild(new CssDeclaration(name, cssValue, node.span,
valueSpanForMap: _expressionSpan(node.value)));
} else if (name.value.startsWith('--')) {
throw _exception(
"Custom property values may not be empty.", node.value.span);
}
if (node.children != null) {