merged branch kosssi/bugfix/css-selector-empty (PR #6271)

This PR was squashed before being merged into the 2.0 branch (closes #6271).

Commits
-------

dbafc2c [CssSelector] added css selector with empty string

Discussion
----------

[CssSelector] added css selector with empty string

---------------------------------------------------------------------------

by kosssi at 2012-12-14T18:29:40Z

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT

---------------------------------------------------------------------------

by stloyd at 2013-01-07T08:21:56Z

@fabpot ping

---------------------------------------------------------------------------

by fabpot at 2013-01-07T10:28:54Z

Sorry, but I don't understand the use case.

---------------------------------------------------------------------------

by kosssi at 2013-01-07T10:36:31Z

if you have this code :
    \<img src="..." alt="">

you can find
    $this->assertCount(1, $crawler->filter('img[alt=""]'));

---------------------------------------------------------------------------

by fabpot at 2013-01-07T10:40:12Z

Then, can you change the unit test with the real use case?

---------------------------------------------------------------------------

by kosssi at 2013-01-07T11:05:50Z

I don't know if it suits you

---------------------------------------------------------------------------

by fabpot at 2013-01-07T11:07:11Z

thanks
This commit is contained in:
Fabien Potencier 2013-01-07 12:07:21 +01:00
commit 5ec6b2a050
2 changed files with 2 additions and 1 deletions

View File

@ -129,7 +129,7 @@ class Tokenizer
}
$result = substr($s, $start, $next - $start);
if ('\\' === $result[strlen($result) - 1]) {
if (strlen($result) > 0 && '\\' === $result[strlen($result) - 1]) {
// next quote character is escaped
$pos = $next + 1;
continue;

View File

@ -34,6 +34,7 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals('foo[class=foo bar ]', $this->tokensToString($this->tokenizer->tokenize('foo[class="foo bar"]')), '->tokenize() lexes an input string and returns an array of tokens');
$this->assertEquals("foo[class=foo Abar ]", $this->tokensToString($this->tokenizer->tokenize('foo[class="foo \\65 bar"]')), '->tokenize() lexes an input string and returns an array of tokens');
$this->assertEquals("img[alt= ]", $this->tokensToString($this->tokenizer->tokenize('img[alt=""]')), '->tokenize() lexes an input string and returns an array of tokens');
}
/**