Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from webimpress/hotfix/descendant-selector
Browse files Browse the repository at this point in the history
Descendant selector with spaces
  • Loading branch information
weierophinney committed Apr 9, 2018
2 parents 3c63c60 + 63cc6a1 commit 2209d79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Document/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function ($matches) use ($placeholder) {
);

$paths = ['//'];
$path = preg_replace('|\s+>\s+|', '>', $path);
$path = preg_replace('|\s*>\s*|', '>', $path);
$segments = preg_split('/\s+/', $path);
$segments = str_replace($placeholder, ' ', $segments);

Expand Down
19 changes: 16 additions & 3 deletions test/Document/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,26 @@ public function testShouldAllowMatchingOfAttributeValues()
$this->assertEquals("//tag[@id='id']//@attribute", $test);
}

public function descendantSelector()
{
yield 'space before' => ['child >leaf'];
yield 'space after' => ['child> leaf'];
yield 'no spaces' => ['child>leaf'];
yield 'with spaces' => ['child > leaf'];
yield 'more spaces' => ['child > leaf'];
}

/**
* @group ZF-8006
*
* @dataProvider descendantSelector
*
* @param string $path
*/
public function testShouldAllowWhitespaceInDescendantSelectorExpressions()
public function testShouldAllowWhitespaceInDescendantSelectorExpressions($path)
{
$test = Query::cssToXpath('child > leaf');
$this->assertEquals("//child/leaf", $test);
$test = Query::cssToXpath($path);
$this->assertEquals('//child/leaf', $test);
}

/**
Expand Down

0 comments on commit 2209d79

Please sign in to comment.