Explorar o código

[DomCrawler] fix finding charset in addContent

Alexey Popkov %!s(int64=13) %!d(string=hai) anos
pai
achega
81fb8e16e7

+ 3 - 0
src/Symfony/Component/DomCrawler/Crawler.php

@@ -92,6 +92,9 @@ class Crawler extends \SplObjectStorage
         $charset = 'ISO-8859-1';
         if (false !== $pos = strpos($type, 'charset=')) {
             $charset = substr($type, $pos + 8);
+            if (false !== $pos = strpos($charset, ';')) {
+                $charset = substr($charset, 0, $pos);
+            }
         }
 
         if ('x' === $matches[1]) {

+ 4 - 0
tests/Symfony/Tests/Component/DomCrawler/CrawlerTest.php

@@ -89,6 +89,10 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
         $crawler->addContent('<html><div class="foo"></html>', 'text/html; charset=UTF-8');
         $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() adds nodes from an HTML string');
 
+        $crawler = new Crawler();
+        $crawler->addContent('<html><div class="foo"></html>', 'text/html; charset=UTF-8; dir=RTL');
+        $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() adds nodes from an HTML string with extended content type');
+
         $crawler = new Crawler();
         $crawler->addContent('<html><div class="foo"></html>');
         $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addContent() uses text/html as the default type');