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

Commit

Permalink
Merge branch 'hotfix/23'
Browse files Browse the repository at this point in the history
Close #23
  • Loading branch information
weierophinney committed Apr 9, 2018
2 parents 3c63c60 + 0801573 commit ec2c66c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ All notable changes to this project will be documented in this file, in reverse
tokenizer marks multiple words within attribute values in order to be
more robust.

- [#23](https://github.com/zendframework/zend-dom/pull/23) fixes an issue with
how descendant selectors work, ensuring spaces may be used around the `>`
operator.

## 2.7.0 - 2018-03-27

### Added
Expand Down
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 ec2c66c

Please sign in to comment.