Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.4

Bug #1084 parseSelectors incorrectly assumes selector structure
Submitted: 2004-03-27 16:03 UTC
From: matt at sensibleerection dot com Assigned: thesaur
Status: Closed Package: HTML_CSS
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 44 - 30 = ?

 
 [2004-03-27 16:03 UTC] matt at sensibleerection dot com
Description: ------------ parseSelectors allows only one instance of each of element, class, id and pseudo in a selector, and presumes a specific order. Reproduce code: --------------- require_once( "HTML/CSS.php" ); $css = new HTML_CSS; $a = $css->parseSelectors( "#heading .shortname" ); $b = $css->parseSelectors( "#heading .icon" ); $c = $css->parseSelectors( "#heading .icon img" ); Expected result: ---------------- #heading .shortname #heading .icon #heading .icon img Actual result: -------------- #heading #heading #heading

Comments

 [2004-03-27 21:46 UTC] thesaur at php dot net
Yeah, I knew there was a problem, but I wasn't exactly sure how it should work in the end. The reason you see what you see is that there should be no reason why anyone needs to implement a class for an ID. Of course, dynamic pseudo classes are a different story (e.g., :hover). Then there is the issue of cascading style sheets which is at the center of your bug report. Selectors may be separated by spaces and then refer to a chain of conditions that must apply before the style is applied. I will rework the parseSelectors to parse each of the cascaded selectors, as well.
 [2004-03-29 04:16 UTC] matt at sensibleerection dot com
In this case it's not the id that's having a class applied, but a descendent of the id (The difference between "#heading.shortname" and "#heading .shortname". Note the space separator in the second.). Referring to a class descendent of an id does often make sense. As you may have several ".shortname" classed elements in the page, but you only want to refer to the ones that are descendents of "#heading".
 [2004-03-29 14:08 UTC] thesaur at php dot net
Which is what I was referring to as cascading selectors. Currently, cascading like that is disabled. But that does not mean that the class expects a certain order. It only places limitations on an individual selector, not space delimited selectors. The current (dumb) workaround is to use a class, because everything after the "." in the initial selector gets passed on unaltered. Of course, this is very unacceptable, but that's the workaround I can offer until I implement a comprehensive solution.
 [2004-05-18 18:58 UTC] joey
This has now been fixed in CVS. I committed changes that upgrade the api if output mode is 2. Now if cascaded selectors are passed, it properly parses them and if outputMode is 2, they are returned as an array instead of the usual element/id/class array keys. This array is assigned to \'inheritance\', with the array elements in the order they are given. The following code: <?php require \'HTML/CSS.php\'; $css = new HTML_CSS(); print_r($css->parseSelectors(\'body, p div .class \', 2)); ?> will now output this: Array ( [0] => Array ( [element] => body [class] => [id] => [pseudo] => ) [1] => Array ( [inheritance] => Array ( [0] => Array ( [element] => p [class] => [id] => [pseudo] => ) [1] => Array ( [element] => div [class] => [id] => [pseudo] => ) [2] => Array ( [element] => .class [class] => [id] => [pseudo] => ) ) ) ) Modes 0 and 1 will return as expected. (0 returns a string, 1 returns an array of selector strings)