diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2019-02-18 00:40:20 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2019-02-18 00:40:20 +0000 |
commit | f3cdd740161f3f401b92e8a849c6e0478dddedb0 (patch) | |
tree | b63bfc068b875e3f7c38f1412ba38fbe92c6936c | |
parent | d5e731f328e14cc8b9898aaa033006df25fc5da5 (diff) | |
download | libcss-f3cdd740161f3f401b92e8a849c6e0478dddedb0.tar.gz libcss-f3cdd740161f3f401b92e8a849c6e0478dddedb0.tar.bz2 |
Parse: fix handling of EOF
-rw-r--r-- | src/parse/parse.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/parse/parse.c b/src/parse/parse.c index afc6d72..def9895 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -927,21 +927,19 @@ css_error parseRuleset(css_parser *parser) if (error != CSS_OK) return error; - if (token->type == CSS_TOKEN_EOF) { + if (token->type != CSS_TOKEN_CHAR || + lwc_string_length(token->idata) != 1 || + lwc_string_data(token->idata)[0] != '{') { + /* FOLLOW(selector) contains only '{', but we may + * also have seen EOF, which is a parse error. */ error = pushBack(parser, token); if (error != CSS_OK) return error; + parser->parseError = true; return done(parser); } - if (token->type != CSS_TOKEN_CHAR || - lwc_string_length(token->idata) != 1 || - lwc_string_data(token->idata)[0] != '{') { - /* This should never happen, as FOLLOW(selector) - * contains only '{' */ - assert(0 && "Expected {"); - } state->substate = WS; /* Fall through */ @@ -1961,6 +1959,9 @@ css_error parseAny1(css_parser *parser) if (error != CSS_OK) return error; + if (token->type == CSS_TOKEN_EOF) + return done(parser); + /* Grammar ambiguity: any0 can be followed by * '{', ';', ')', ']'. any1 can only be followed by '{'. */ if (token->type == CSS_TOKEN_CHAR && @@ -2080,6 +2081,17 @@ css_error parseAny(css_parser *parser) if (error != CSS_OK) return error; + if (token->type == CSS_TOKEN_EOF) { + error = pushBack(parser, token); + if (error != CSS_OK) + return error; + + /* parse error */ + parser->parseError = true; + + return done(parser); + } + /* Match correct close bracket (grammar ambiguity) */ if (token->type == CSS_TOKEN_CHAR && lwc_string_length(token->idata) == 1 && |