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

Commit

Permalink
Prevents exception for invalid dimension terms
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leonsenft committed May 8, 2017
1 parent 21dc8ce commit cd6daad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ class _Parser {
break;
}

return processDimension(t, value, _makeSpan(start));
return t != null ? processDimension(t, value, _makeSpan(start)) : null;
}

/** Process all dimension units. */
Expand Down
11 changes: 11 additions & 0 deletions test/declaration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, '%');
}

/**
Expand Down

0 comments on commit cd6daad

Please # to comment.