diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/seleng/cr-sel-eng.c | 122 | ||||
-rw-r--r-- | tests/test-inputs/test5.1.css | 1 | ||||
-rw-r--r-- | tests/test-output-refs/test5.1.css.out | 5 |
4 files changed, 89 insertions, 46 deletions
@@ -3,7 +3,12 @@ * docs/examples/selection-example-1.c: a bit of cleanup and bug fix here. * docs/examples/selection-example-1.css: added more test cases. - + * src/seleng/cr-sel-eng.c: + (additional_selector_matches_node): added this function to + factorise the evaluation of additional selectors. + (sel_matches_node_real ): use additional_selector_matches_node(). + This fixes a selector bug spotted by Stefan Seefeld. + 2003-12-11 Dodji Seketeli <dodji@gnome.org> * configure.in: updated version numbers for 0.4. diff --git a/src/seleng/cr-sel-eng.c b/src/seleng/cr-sel-eng.c index 5907596..9711955 100644 --- a/src/seleng/cr-sel-eng.c +++ b/src/seleng/cr-sel-eng.c @@ -329,6 +329,67 @@ attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, } /** + *Evaluates if a given additional selector matches an xml node. + *@param a_add_sel the additional selector to consider. + *@param a_node the xml node to consider. + *@return TRUE is a_add_sel matches a_node, FALSE otherwise. + */ +static gboolean +additional_selector_matches_node (CRAdditionalSel *a_add_sel, + xmlNode *a_node) +{ + if (!a_add_sel) + { + return FALSE ; + } + + if (a_add_sel->type == NO_ADD_SELECTOR) + { + return FALSE ; + } + + if (a_add_sel->type == CLASS_ADD_SELECTOR + && a_add_sel->content.class_name + && a_add_sel->content.class_name->str) + { + if (class_add_sel_matches_node + (a_add_sel, a_node) == FALSE) + { + return FALSE ; + } + return TRUE ; + } + else if (a_add_sel->type == ID_ADD_SELECTOR + && a_add_sel->content.id_name + && a_add_sel->content.id_name->str) + { + if (id_add_sel_matches_node + (a_add_sel, a_node) == FALSE) + { + return FALSE ; + } + return TRUE ; + } + else if (a_add_sel->type == ATTRIBUTE_ADD_SELECTOR + && a_add_sel->content.attr_sel) + { + /* + *here, call a function that does the match + *against an attribute additionnal selector + *and an xml node. + */ + if (attr_add_sel_matches_node + (a_add_sel, a_node) + == FALSE) + { + return FALSE ; + } + return TRUE ; + } + return FALSE ; +} + +/** *Evaluate a selector (a simple selectors list) and says *if it matches the xml node given in parameter. *The algorithm used here is the following: @@ -397,7 +458,16 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, *simple selectors also match *their xml node counterpart. */ - goto walk_a_step_in_expr ; + if (cur_sel->add_sel) { + if (additional_selector_matches_node + (cur_sel->add_sel, cur_node) == TRUE) { + goto walk_a_step_in_expr ; + } else { + goto done ; + } + } else { + goto walk_a_step_in_expr ; + } } goto done ; } @@ -411,51 +481,13 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, { goto done ; } - - if (cur_sel->add_sel->type == NO_ADD_SELECTOR) - { - goto done ; - } - - if (cur_sel->add_sel->type == CLASS_ADD_SELECTOR - && cur_sel->add_sel->content.class_name - && cur_sel->add_sel->content.class_name->str) - { - if (class_add_sel_matches_node - (cur_sel->add_sel, cur_node) == FALSE) - { - goto done ; - } + if (additional_selector_matches_node + (cur_sel->add_sel, cur_node) == TRUE) { goto walk_a_step_in_expr ; - } - else if (cur_sel->add_sel->type == ID_ADD_SELECTOR - && cur_sel->add_sel->content.id_name - && cur_sel->add_sel->content.id_name->str) - { - if (id_add_sel_matches_node - (cur_sel->add_sel, cur_node) == FALSE) - { - goto done; - } - goto walk_a_step_in_expr ; - } - else if (cur_sel->add_sel->type == ATTRIBUTE_ADD_SELECTOR - && cur_sel->add_sel->content.attr_sel) - { - /* - *here, call a function that does the match - *against an attribute additionnal selector - *and an xml node. - */ - if (attr_add_sel_matches_node - (cur_sel->add_sel, cur_node) - == FALSE) - { - goto done ; - } - goto walk_a_step_in_expr ; - } - + } else { + goto done ; + } + walk_a_step_in_expr: if (a_recurse == FALSE) { diff --git a/tests/test-inputs/test5.1.css b/tests/test-inputs/test5.1.css index b557b26..e6468fd 100644 --- a/tests/test-inputs/test5.1.css +++ b/tests/test-inputs/test5.1.css @@ -3,6 +3,7 @@ [attr4|=val4] {prop7: val7} [attr3~=val3_2] {prop6: val6} [attr2=val2] {prop5: val5} +E2[attr2=val2] {prop8: val8} E0 {prop0: val0} E0+E1{pro1:val1} E1 E1-1 {prop2: val2} diff --git a/tests/test-output-refs/test5.1.css.out b/tests/test-output-refs/test5.1.css.out index b91b4fe..bb1d76f 100644 --- a/tests/test-output-refs/test5.1.css.out +++ b/tests/test-output-refs/test5.1.css.out @@ -50,6 +50,11 @@ xml start element: E2 prop5 : val5 } + + E2[attr2="val2"] { + prop8 : val8 + } + xml end element: E2 ''''''''''''''''''''''''' ''''''''''''''''''''''''' |