diff --git a/lib/parser.dart b/lib/parser.dart index 3dff61e..cd4f6c0 100644 --- a/lib/parser.dart +++ b/lib/parser.dart @@ -2475,7 +2475,7 @@ class _Parser { break; } - return processDimension(t, value, _makeSpan(start)); + return t != null ? processDimension(t, value, _makeSpan(start)) : null; } /** Process all dimension units. */ diff --git a/test/declaration_test.dart b/test/declaration_test.dart index 733a198..af6fdef 100644 --- a/test/declaration_test.dart +++ b/test/declaration_test.dart @@ -69,6 +69,17 @@ void testSimpleTerms() { expect(stylesheet != null, true); expect(errors.isEmpty, true, reason: errors.toString()); expect(prettyPrint(stylesheet), generated2); + + // Regression test to ensure invalid percentages don't throw an exception and + // instead print a useful error message when not in checked mode. + var css = ''' +.foo { + width: Infinity%; +}'''; + stylesheet = parseCss(css, errors: errors..clear(), opts: simpleOptions); + expect(errors, isNotEmpty); + expect(errors.first.message, 'expected }, but found %'); + expect(errors.first.span.text, '%'); } /**