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

Descendant selector with spaces #23

Merged
merged 1 commit into from Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Document/Query.php
Expand Up @@ -96,7 +96,7 @@ function ($matches) {
);

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

Expand Down
19 changes: 16 additions & 3 deletions test/Document/QueryTest.php
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