Skip to content

Commit

Permalink
[DomCrawler] Added test for supported encodings by mbstring
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Sep 25, 2012
1 parent 237629a commit d7623ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/Crawler.php
Expand Up @@ -132,7 +132,7 @@ public function addHtmlContent($content, $charset = 'UTF-8')
$dom = new \DOMDocument('1.0', $charset);
$dom->validateOnParse = true;

if (function_exists('mb_convert_encoding')) {
if (function_exists('mb_convert_encoding') && in_array(strtolower($charset), array_map('strtolower', mb_list_encodings()))) {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Expand Up @@ -80,6 +80,17 @@ public function testAddHtmlContentCharset()
$this->assertEquals('Tiếng Việt', $crawler->filterXPath('//div')->text());
}

/**
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
*/
public function testAddHtmlContentUnsupportedCharset()
{
$crawler = new Crawler();
$crawler->addHtmlContent(file_get_contents(__DIR__.'/Fixtures/windows-1250.html'), 'Windows-1250');

$this->assertEquals('Žťčýů', $crawler->filterXPath('//p')->text());
}

/**
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
*/
Expand Down
@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=windows-1250">
</head>
<body>
<p>Žèýù</p>
</body>
</html>

0 comments on commit d7623ae

Please sign in to comment.