소스 검색

merged branch kreischweide/fnf-parse-exception (PR #1478)

Commits
-------

19f5d82 Fix
08bbb19 UnitTest

Discussion
----------

[CssSelector] Fatal error on invalid selector expression

The following usage in a WebTestCase leads to a fatal error and ends phpunit:

```
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$this->assertTrue($crawler->filter('/invalid')->count() > 0);
```

2 commits made, first one is the UnitTest to check on correct exception throwing, second one to fix the wrong namespace.
Fabien Potencier 14 년 전
부모
커밋
fdd92627b7
2개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      src/Symfony/Component/CssSelector/Tokenizer.php
  2. 8 0
      tests/Symfony/Tests/Component/CssSelector/TokenizerTest.php

+ 1 - 1
src/Symfony/Component/CssSelector/Tokenizer.php

@@ -189,7 +189,7 @@ class Tokenizer
         $matchStart = $match[0][1];
 
         if ($matchStart == $pos) {
-            throw new ParseException(sprintf('Unexpected symbol: %s at %s', $s[$pos], $pos));
+            throw new Exception\ParseException(sprintf('Unexpected symbol: %s at %s', $s[$pos], $pos));
         }
 
         $result = substr($s, $start, $matchStart - $start);

+ 8 - 0
tests/Symfony/Tests/Component/CssSelector/TokenizerTest.php

@@ -36,6 +36,14 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
         $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');
     }
 
+    /**
+     * @expectedException Symfony\Component\CssSelector\Exception\ParseException
+     */
+    public function testTokenizeInvalidString()
+    {
+        $this->tokensToString($this->tokenizer->tokenize('/invalid'));
+    }
+
     public function getCssSelectors()
     {
         return array(