Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added comma implementation

  • Loading branch information...
commit f792eebbe01be1fee36d0b7224f4da0f856dd0cb 1 parent e6bc94f
@tj authored
Showing with 6 additions and 0 deletions.
  1. +2 −0  selector.inc
  2. +4 −0 test.selector.php
View
2  selector.inc
@@ -82,6 +82,8 @@ function element_to_array($element) {
function selector_to_xpath($selector) {
$selector = 'descendant-or-self::' . $selector;
+ // ,
+ $selector = preg_replace('/\s*,\s*/', '|descendant-or-self::', $selector);
// :button, :submit, etc
$selector = preg_replace('/:(button|submit|file|checkbox|radio|image|reset|text|password)/', 'input[@type="\1"]', $selector);
// [id]
View
4 test.selector.php
@@ -14,6 +14,7 @@ function test($selector, $expected) {
}
test('foo', 'descendant-or-self::foo');
+test('foo, bar', 'descendant-or-self::foo|descendant-or-self::bar');
test('foo bar', 'descendant-or-self::foo/descendant::bar');
test('foo bar', 'descendant-or-self::foo/descendant::bar');
test('foo > bar', 'descendant-or-self::foo/bar');
@@ -62,6 +63,9 @@ function test($selector, $expected) {
test_selector('*', 12);
test_selector('div', 1);
+test_selector('div, p', 2);
+test_selector('div , p', 2);
+test_selector('div ,p', 2);
test_selector('div#article', 1);
test_selector('div#article.block', 1);
test_selector('div#article.large.block', 1);
Please sign in to comment.
Something went wrong with that request. Please try again.