changeset 753:8d0cce1b9129

refactor Css_parse_selector() to avoid looping Make sure that even if parsing of a CSS selector fails, the parser advances until the end of the selector (EOF, ',', or '{').
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 12 Jan 2009 13:23:52 +0100
parents 7c51158d1466
children 336ae7ab06a8
files src/cssparser.cc
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/cssparser.cc	Sun Jan 11 21:05:55 2009 +0100
+++ b/src/cssparser.cc	Mon Jan 12 13:23:52 2009 +0100
@@ -1045,12 +1045,15 @@
    CssSelector *selector = new CssSelector ();
 
    while (true) {
-      if (! Css_parse_simple_selector (parser, selector->top ()))
-         Css_next_token(parser); /* make sure we advance at least one token */
+      if (! Css_parse_simple_selector (parser, selector->top ())) {
+         delete selector;
+         selector = NULL;
+         break;
+      }
 
       if (parser->ttype == CSS_TK_CHAR &&
          (parser->tval[0] == ',' || parser->tval[0] == '{')) {
-         return selector;
+         break;
       } else if (parser->ttype == CSS_TK_CHAR && parser->tval[0] == '>') {
          selector->addSimpleSelector (CssSelector::CHILD);
          Css_next_token(parser);
@@ -1058,10 +1061,16 @@
          selector->addSimpleSelector (CssSelector::DESCENDENT);
       } else {
          delete selector;
-         return NULL;
+         selector = NULL;
+         break;
       }
    }
 
+   while (parser->ttype != CSS_TK_END &&
+          (parser->ttype != CSS_TK_CHAR ||
+           (parser->tval[0] != ',' && parser->tval[0] != '{')))
+         Css_next_token(parser);
+
    return selector;
 }