Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[DomCrawler] Fixed charset detection in html5 meta charset tag

  • Loading branch information...
commit 172e75208aced6f0cbe7d8c49034240d611c0286 1 parent 29341fa
@77web 77web authored fabpot committed
View
4 src/Symfony/Component/DomCrawler/Crawler.php
@@ -108,8 +108,10 @@ public function addContent($content, $type = null)
}
}
+ // http://www.w3.org/TR/encoding/#encodings
+ // http://www.w3.org/TR/REC-xml/#NT-EncName
if (null === $charset &&
- preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $content, $matches)) {
+ preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9_:.]+)/i', $content, $matches)) {
$charset = $matches[1];
}
View
4 src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
@@ -232,6 +232,10 @@ public function testAddContent()
$crawler = new Crawler();
$crawler->addContent('<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><span>中文</span></html>');
$this->assertEquals('中文', $crawler->filterXPath('//span')->text(), '->addContent() guess wrong charset');
+
+ $crawler = new Crawler();
+ $crawler->addContent(mb_convert_encoding('<html><head><meta charset="Shift_JIS"></head><body>日本語</body></html>', 'SJIS', 'UTF-8'));
+ $this->assertEquals('日本語', $crawler->filterXPath('//body')->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.