Permalink
Browse files

support for KS_C_5601-1987,

  • Loading branch information...
1 parent 865fc34 commit 7d90bfc38db243b2211fef74b57044a4357ed66f @sasezaki sasezaki committed Oct 27, 2012
@@ -34,9 +34,14 @@ class HtmlDetector
*/
private $_detectOrder = 'ASCII, JIS, UTF-8, eucJP-win, EUC-JP, SJIS-win, SJIS';
- private $_config = array('accept_header_ctype' => true,
- 'force_detect_body' => false,
- 'detect_prefer_mime' => false);
+ private $_config = array(
+ 'accept_header_ctype' => true,
+ 'force_detect_body' => false,
+ 'detect_prefer_mime' => false,
+ 'iconv_map' => array(
+ 'KS_C_5601-1987' => 'CP949',
+ ),
+ );
/**
* configure
@@ -178,6 +183,12 @@ public function detect($responseBody, $contentType = null)
//if ($wellknown = array_search($encoding, array('HZ-GB-2312' => 'GB-2312'))) {
// return $wellknown;
//}
+
+ if (is_array($this->_config['iconv_map']) &&
+ in_array(strtoupper($encoding), array_keys($this->_config['iconv_map']))) {
+ $encoding = $this->_config['iconv_map'][strtoupper($encoding)];
+ }
+
return $encoding;
}
@@ -8,16 +8,8 @@ class HtmlDetectorTest extends \PHPUnit_Framework_TestCase
private $detectOrder;
- protected function setUp()
- {
- }
-
- protected function tearDown()
- {
- }
-
/**
- * test "detect" part.1
+ * "detect" when only response body available
*/
public function testDetectOnlyResponseBody()
{
@@ -91,10 +83,9 @@ public function testDetectWithHeadersContentType()
$detector->detect($bodySJIS, $ctype));
}
- public function testSetDetectOrder() {
-
+ public function testSetDetectOrder()
+ {
$detector = new HtmlDetector();
-
$this->assertEquals(HtmlDetector::DEFAULT_DETECT_ORDER,
$detector->getDetectOrder());
@@ -109,6 +100,15 @@ public function testSetDetectOrder() {
$detector->getDetectOrder());
}
-}
+ public function testIconMap()
+ {
+ $detector = new HtmlDetector();
+ $bodyCP949 = iconv('UTF-8', 'CP949', '플랫폼에서는');
+ $charset = 'KS_C_5601-1987';
+ $ctype = "text/html; charset=$charset;";
+ $detect = $detector->detect($bodyCP949, $ctype);
+ $this->assertEquals('CP949', $detect, 'detect should iconv handle available');
+ }
+}

0 comments on commit 7d90bfc

Please sign in to comment.