Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit cd6daad

Browse files
committed
Prevents exception for invalid dimension terms
While running outside of checked mode, parsing an invalid term expression followed by a known dimension unit like width: Infinity%; caused the following exception to be thrown: The getter 'text' was called on null. Receiver: null Instead the parser now discards the invalid term, likely resulting in a useful error message indicating the source of failure such as error on ...: expected }, but found % width: Infinity%; ^ Fixes #43.
1 parent 21dc8ce commit cd6daad

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/parser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ class _Parser {
24762476
break;
24772477
}
24782478

2479-
return processDimension(t, value, _makeSpan(start));
2479+
return t != null ? processDimension(t, value, _makeSpan(start)) : null;
24802480
}
24812481

24822482
/** Process all dimension units. */

test/declaration_test.dart

+11
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ void testSimpleTerms() {
6969
expect(stylesheet != null, true);
7070
expect(errors.isEmpty, true, reason: errors.toString());
7171
expect(prettyPrint(stylesheet), generated2);
72+
73+
// Regression test to ensure invalid percentages don't throw an exception and
74+
// instead print a useful error message when not in checked mode.
75+
var css = '''
76+
.foo {
77+
width: Infinity%;
78+
}''';
79+
stylesheet = parseCss(css, errors: errors..clear(), opts: simpleOptions);
80+
expect(errors, isNotEmpty);
81+
expect(errors.first.message, 'expected }, but found %');
82+
expect(errors.first.span.text, '%');
7283
}
7384

7485
/**

0 commit comments

Comments
 (0)