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/5351' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/Css2Xpath.php
Expand Up @@ -85,7 +85,7 @@ protected static function _tokenize($expression)

// arbitrary attribute strict equality
$expression = preg_replace_callback(
'|\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
'|\[@?([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
function ($matches) {
return '[@' . strtolower($matches[1]) . "='" . $matches[2] . "']";
},
Expand Down Expand Up @@ -113,11 +113,13 @@ function ($matches) {
);

// Classes
$expression = preg_replace(
'|\.([a-z][a-z0-9_-]*)|i',
"[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]",
$expression
);
if(false === strpos($expression, "[@")) {
$expression = preg_replace(
'|\.([a-z][a-z0-9_-]*)|i',
"[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]",
$expression
);
}

/** ZF-9764 -- remove double asterisk */
$expression = str_replace('**', '*', $expression);
Expand Down
12 changes: 12 additions & 0 deletions test/Css2XpathTest.php
Expand Up @@ -164,4 +164,16 @@ public function testIdSelectorWithLeadingAsterix()
$test = Css2Xpath::transform('*#id');
$this->assertEquals("//*[@id='id']", $test);
}

/**
* @group ZF-5310
*/
public function testCanTransformWithAttributeAndDot()
{
$test = Css2Xpath::transform('a[href="http://example.com"]');
$this->assertEquals("//a[@href='http://example.com']", $test);

$test = Css2Xpath::transform('a[@href="http://example.com"]');
$this->assertEquals("//a[@href='http://example.com']", $test);
}
}
13 changes: 13 additions & 0 deletions test/QueryTest.php
Expand Up @@ -396,4 +396,17 @@ public function testOffsetUnset()

unset($results[2]);
}

/**
* @group ZF-5310
*/
public function testCssSelectorShouldFindNodesWhenMatchingAttributeValueWithDot()
{
$this->loadHtml();
$results = $this->query->execute('a[href="http://www.about.com"]');

$this->assertEquals(1, $results->count());
$this->assertEquals('About', $results[0]->nodeValue);

}
}
2 changes: 1 addition & 1 deletion test/_files/sample.xhtml
Expand Up @@ -16,7 +16,7 @@

<ul id="topnav">
<li class="current"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="http://www.about.com">About</a></li>
<li><a href="#">Misc</a></li>
<li><a href="#">Wiki</a></li>
</ul>
Expand Down

0 comments on commit 47fd133

Please sign in to comment.