diff options
-rw-r--r-- | src/cssparser.cc | 63 | ||||
-rw-r--r-- | src/cssparser.hh | 2 |
2 files changed, 56 insertions, 9 deletions
diff --git a/src/cssparser.cc b/src/cssparser.cc index ed880d17..ec7cb29b 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1443,25 +1443,70 @@ const char * CssParser::propertyNameString(CssPropertyName name) { return Css_property_info[name].symbol; } + +void CssParser::ignoreBlock() +{ + int depth = 0; + + while (ttype != CSS_TK_END) { + if (ttype == CSS_TK_CHAR) { + if (tval[0] =='{') + depth++; + else if (tval[0] =='}') { + depth--; + if (depth == 0) { + nextToken(); + return; + } + } + } + nextToken(); + } +} + +void CssParser::ignoreStatement() +{ + while (ttype != CSS_TK_END) { + if (ttype == CSS_TK_CHAR) { + if (tval[0] == ';') { + nextToken(); + return; + } + else if (tval[0] =='{') { + ignoreBlock(); + return; + } + } + nextToken(); + } +} void CssParser::parse(DilloHtml *html, DilloUrl *url, CssContext * context, const char *buf, int buflen, CssOrigin origin) { CssParser parser (context, origin, buf, buflen); + bool importsAreAllowed = true; - while (parser.ttype == CSS_TK_CHAR && parser.tval[0] == '@') { - parser.nextToken(); - if (html != NULL && - parser.ttype == CSS_TK_SYMBOL && - dStrcasecmp(parser.tval, "import") == 0) { + while (parser.ttype != CSS_TK_END) { + if (parser.ttype == CSS_TK_CHAR && + parser.tval[0] == '@') { parser.nextToken(); - parser.parseImport(html, url); + if (parser.ttype == CSS_TK_SYMBOL && + dStrcasecmp(parser.tval, "import") == 0 && + html != NULL && + importsAreAllowed) { + parser.nextToken(); + parser.parseImport(html, url); + } + else + parser.ignoreStatement(); + } + else { + importsAreAllowed = false; + parser.parseRuleset(); } } - - while (parser.ttype != CSS_TK_END) - parser.parseRuleset(); } CssPropertyList *CssParser::parseDeclarationBlock(const char *buf, int buflen) diff --git a/src/cssparser.hh b/src/cssparser.hh index 1e471c68..9d3feeaf 100644 --- a/src/cssparser.hh +++ b/src/cssparser.hh @@ -42,6 +42,8 @@ class CssParser { void parseImport(DilloHtml *html, DilloUrl *url); CssSelector *parseSelector(); void parseRuleset(); + void ignoreBlock(); + void ignoreStatement(); public: static CssPropertyList *parseDeclarationBlock(const char *buf, |