diff --git a/src/Document/Query.php b/src/Document/Query.php index 7b40a8e..c1ac7d7 100644 --- a/src/Document/Query.php +++ b/src/Document/Query.php @@ -88,7 +88,7 @@ public static function cssToXpath($path) // Arbitrary attribute value contains whitespace $path = preg_replace_callback( - '/\[\S+["\'](.+)["\']\]/', + '/\[\S+?["\'](.+?)["\']\]/', function ($matches) { return str_replace($matches[1], preg_replace('/\s+/', '\s', $matches[1]), $matches[0]); }, diff --git a/test/Document/QueryTest.php b/test/Document/QueryTest.php index afcc7ca..dcb8360 100644 --- a/test/Document/QueryTest.php +++ b/test/Document/QueryTest.php @@ -172,4 +172,10 @@ public function testCanTransformWithAttributeAndDot() $test = Query::cssToXpath('a[@href="http://example.com"]'); $this->assertEquals("//a[@href='http://example.com']", $test); } + + public function testTransformNestedAttributeSelectors() + { + $test = Query::cssToXpath('select[name="foo"] option[selected="selected"]'); + $this->assertEquals("//select[@name='foo']//option[@selected='selected']", $test); + } }