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

Commit

Permalink
Merge pull request #5351 from steverhoades/hotfix/5310
Browse files Browse the repository at this point in the history
fixes #5310
  • Loading branch information
weierophinney committed Oct 28, 2013
2 parents 66f688c + 2ff5261 commit 6fe94dd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
14 changes: 8 additions & 6 deletions library/Zend/Dom/Css2Xpath.php
Original file line number Diff line number Diff line change
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 tests/ZendTest/Dom/Css2XpathTest.php
Original file line number Diff line number Diff line change
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 tests/ZendTest/Dom/QueryTest.php
Original file line number Diff line number Diff line change
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 tests/ZendTest/Dom/_files/sample.xhtml
Original file line number Diff line number Diff line change
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 6fe94dd

Please sign in to comment.