diff --git a/src/Css2Xpath.php b/src/Css2Xpath.php index c2acf15..0b3a775 100644 --- a/src/Css2Xpath.php +++ b/src/Css2Xpath.php @@ -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] . "']"; }, @@ -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); diff --git a/test/Css2XpathTest.php b/test/Css2XpathTest.php index 00f6ed9..c792821 100644 --- a/test/Css2XpathTest.php +++ b/test/Css2XpathTest.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Dom */ namespace ZendTest\Dom; @@ -15,9 +14,6 @@ /** * Test class for Css2Xpath. * - * @category Zend - * @package Zend_Dom - * @subpackage UnitTests * @group Zend_Dom */ class Css2XpathTest extends \PHPUnit_Framework_TestCase @@ -168,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); + } } diff --git a/test/NodeListTest.php b/test/NodeListTest.php index d249a82..06667f5 100644 --- a/test/NodeListTest.php +++ b/test/NodeListTest.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Dom */ namespace ZendTest\Dom; @@ -13,9 +12,6 @@ use Zend\Dom\NodeList; /** - * @category Zend - * @package Zend_Dom - * @subpackage UnitTests * @group Zend_Dom */ class NodeListTest extends \PHPUnit_Framework_TestCase diff --git a/test/QueryTest.php b/test/QueryTest.php index af81594..b67b93c 100644 --- a/test/QueryTest.php +++ b/test/QueryTest.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Dom */ namespace ZendTest\Dom; @@ -17,9 +16,6 @@ /** * Test class for Zend_Dom_Query. * - * @category Zend - * @package Zend_Dom - * @subpackage UnitTests * @group Zend_Dom */ class QueryTest extends \PHPUnit_Framework_TestCase @@ -400,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); + + } } diff --git a/test/_files/sample.xhtml b/test/_files/sample.xhtml index c250c54..9e2432d 100644 --- a/test/_files/sample.xhtml +++ b/test/_files/sample.xhtml @@ -16,7 +16,7 @@