summaryrefslogtreecommitdiff
path: root/source/html/css-parse.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-04-14 20:44:17 +0200
committerTor Andersson <tor.andersson@artifex.com>2015-04-15 17:48:45 +0200
commit1e0b6a6c60c6cb76245cb659458868f92ed0cda0 (patch)
treea0d367c2b23771cce1386893769ff11e323dff5c /source/html/css-parse.c
parentd940388d7747fd3d816fbd7813567a843d30d969 (diff)
downloadmupdf-1e0b6a6c60c6cb76245cb659458868f92ed0cda0.tar.xz
epub: Be resilient in the face of broken CSS.
Try to recover from syntax errors in CSS rules by skipping to the end of the declaration block. Don't abort HTML parsing on CSS errors.
Diffstat (limited to 'source/html/css-parse.c')
-rw-r--r--source/html/css-parse.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/source/html/css-parse.c b/source/html/css-parse.c
index 93916344..d2415676 100644
--- a/source/html/css-parse.c
+++ b/source/html/css-parse.c
@@ -15,7 +15,7 @@ struct lexbuf
FZ_NORETURN static void fz_css_error(struct lexbuf *buf, const char *msg)
{
- fz_throw(buf->ctx, FZ_ERROR_GENERIC, "css syntax error: %s (%s:%d)", msg, buf->file, buf->line);
+ fz_throw(buf->ctx, FZ_ERROR_SYNTAX, "css syntax error: %s (%s:%d)", msg, buf->file, buf->line);
}
static fz_css_rule *fz_new_css_rule(fz_context *ctx, fz_css_selector *selector, fz_css_property *declaration)
@@ -821,13 +821,29 @@ static fz_css_selector *parse_selector_list(struct lexbuf *buf)
static fz_css_rule *parse_rule(struct lexbuf *buf)
{
- fz_css_selector *s;
- fz_css_property *p;
+ fz_css_selector *s = NULL;
+ fz_css_property *p = NULL;
+
+ fz_try(buf->ctx)
+ {
+ s = parse_selector_list(buf);
+ expect(buf, '{');
+ p = parse_declaration_list(buf);
+ expect(buf, '}');
+ }
+ fz_catch(buf->ctx)
+ {
+ if (fz_caught(buf->ctx) != FZ_ERROR_SYNTAX)
+ fz_rethrow(buf->ctx);
+ while (buf->lookahead != EOF)
+ {
+ if (accept(buf, '}'))
+ break;
+ next(buf);
+ }
+ return NULL;
+ }
- s = parse_selector_list(buf);
- expect(buf, '{');
- p = parse_declaration_list(buf);
- expect(buf, '}');
return fz_new_css_rule(buf->ctx, s, p);
}
@@ -882,8 +898,12 @@ static fz_css_rule *parse_stylesheet(struct lexbuf *buf, fz_css_rule *chain)
}
else
{
- rule = *nextp = parse_rule(buf);
- nextp = &rule->next;
+ fz_css_rule *x = parse_rule(buf);
+ if (x)
+ {
+ rule = *nextp = x;
+ nextp = &rule->next;
+ }
}
}