summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2019-02-18 00:40:20 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2019-03-10 13:42:03 +0000
commit32221bc146be61fba1296c58ed072cdf84b4de6f (patch)
treee3c682901ad7edce56162de2f06d40e285f28a78
parent861681b2717ed605f26af326d82d9b2009714c2e (diff)
downloadlibcss-32221bc146be61fba1296c58ed072cdf84b4de6f.tar.gz
libcss-32221bc146be61fba1296c58ed072cdf84b4de6f.tar.bz2
Parse: fix handling of EOF
-rw-r--r--src/parse/parse.c28
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 &&