From 1cb7f8f9ae768b680477212c678a3111fca71ef7 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 27 Nov 2014 15:56:06 +0100 Subject: html: Fix parsing of @-rules in CSS. --- source/html/css-parse.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'source/html') diff --git a/source/html/css-parse.c b/source/html/css-parse.c index db17e431..18f33e16 100644 --- a/source/html/css-parse.c +++ b/source/html/css-parse.c @@ -789,42 +789,30 @@ static fz_css_rule *parse_rule(struct lexbuf *buf) return fz_new_css_rule(buf->ctx, s, p); } -static void parse_media_list(struct lexbuf *buf) -{ - fz_css_rule *r; - - while (buf->lookahead != '}' && buf->lookahead != EOF) - { - r = parse_rule(buf); - fz_free_css(buf->ctx, r); - } -} - static void parse_at_rule(struct lexbuf *buf) { - fz_css_property *p; - fz_css_value *v; - expect(buf, CSS_KEYWORD); - if (accept(buf, '{')) /* @page */ - { - p = parse_declaration_list(buf); - fz_free_css_property(buf->ctx, p); - expect(buf, '}'); - } - else + + /* skip until '{' or ';' */ + while (buf->lookahead != EOF) { - v = parse_value_list(buf); - fz_free_css_value(buf->ctx, v); - if (accept(buf, '{')) /* @media */ + if (accept(buf, ';')) + return; + if (accept(buf, '{')) { - parse_media_list(buf); - expect(buf, '}'); - } - else /* @import */ - { - expect(buf, ';'); + int depth = 1; + while (buf->lookahead != EOF && depth > 0) + { + if (accept(buf, '{')) + ++depth; + else if (accept(buf, '}')) + --depth; + else + next(buf); + } + return; } + next(buf); } } -- cgit v1.2.3