Skip to content

Commit

Permalink
[CssSelector] fixed CssSelector::toXPath() when the CSS selector is a…
Browse files Browse the repository at this point in the history
…n empty string
  • Loading branch information
fabpot committed Mar 11, 2012
1 parent 1b9b428 commit a827375
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/CssSelector/CssSelector.php
Expand Up @@ -45,6 +45,10 @@ class CssSelector
static public function toXPath($cssExpr, $prefix = 'descendant-or-self::')
{
if (is_string($cssExpr)) {
if (!$cssExpr) {
return $prefix.'*';
}

if (preg_match('#^\w+\s*$#u', $cssExpr, $match)) {
return $prefix.trim($match[0]);
}
Expand Down
Expand Up @@ -17,6 +17,7 @@ class CssSelectorTest extends \PHPUnit_Framework_TestCase
{
public function testCsstoXPath()
{
$this->assertEquals('descendant-or-self::*', CssSelector::toXPath(''));
$this->assertEquals('descendant-or-self::h1', CssSelector::toXPath('h1'));
$this->assertEquals("descendant-or-self::h1[@id = 'foo']", CssSelector::toXPath('h1#foo'));
$this->assertEquals("descendant-or-self::h1[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]", CssSelector::toXPath('h1.foo'));
Expand Down

0 comments on commit a827375

Please sign in to comment.