mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-23 14:27:02 +00:00
- Add Test namespace
- Further fix the no iconv problem, and extend test cases to cover that case. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@368 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
fdd583253c
commit
4f0a5c0e22
@ -46,6 +46,7 @@ class HTMLPurifier_ConfigDef {
|
|||||||
$this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
|
$this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
|
||||||
$this->defineNamespace('HTML', 'Configuration regarding allowed HTML.');
|
$this->defineNamespace('HTML', 'Configuration regarding allowed HTML.');
|
||||||
$this->defineNamespace('CSS', 'Configuration regarding allowed CSS.');
|
$this->defineNamespace('CSS', 'Configuration regarding allowed CSS.');
|
||||||
|
$this->defineNamespace('Test', 'Testing configuration for our unit tests.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,12 @@ if ( !function_exists('iconv') ) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigDef::define(
|
||||||
|
'Test', 'ForceNoIconv', false, 'bool',
|
||||||
|
'When set to true, HTMLPurifier_Encoder will act as if iconv does not '.
|
||||||
|
'exist and use only pure PHP implementations.'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A UTF-8 specific character encoder that handles cleaning and transforming.
|
* A UTF-8 specific character encoder that handles cleaning and transforming.
|
||||||
*/
|
*/
|
||||||
@ -265,9 +271,9 @@ class HTMLPurifier_Encoder
|
|||||||
if ($iconv === null) $iconv = function_exists('iconv');
|
if ($iconv === null) $iconv = function_exists('iconv');
|
||||||
$encoding = $config->get('Core', 'Encoding');
|
$encoding = $config->get('Core', 'Encoding');
|
||||||
if ($encoding === 'utf-8') return $str;
|
if ($encoding === 'utf-8') return $str;
|
||||||
if ($iconv) {
|
if ($iconv && !$config->get('Test', 'ForceNoIconv')) {
|
||||||
return @iconv($encoding, 'utf-8//IGNORE', $str);
|
return @iconv($encoding, 'utf-8//IGNORE', $str);
|
||||||
} elseif ($encoding === 'iso-8895-1') {
|
} elseif ($encoding === 'iso-8859-1') {
|
||||||
return @utf8_encode($str);
|
return @utf8_encode($str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,10 +288,10 @@ class HTMLPurifier_Encoder
|
|||||||
if ($iconv === null) $iconv = function_exists('iconv');
|
if ($iconv === null) $iconv = function_exists('iconv');
|
||||||
$encoding = $config->get('Core', 'Encoding');
|
$encoding = $config->get('Core', 'Encoding');
|
||||||
if ($encoding === 'utf-8') return $str;
|
if ($encoding === 'utf-8') return $str;
|
||||||
if ($iconv) {
|
if ($iconv && !$config->get('Test', 'ForceNoIconv')) {
|
||||||
return @iconv('utf-8', $encoding . '//IGNORE', $str);
|
return @iconv('utf-8', $encoding . '//IGNORE', $str);
|
||||||
} elseif ($encoding === 'iso-8895-1') {
|
} elseif ($encoding === 'iso-8859-1') {
|
||||||
return @utf8_encode($str);
|
return @utf8_decode($str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,14 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
$this->Encoder->convertToUTF8("\xF6", $config),
|
$this->Encoder->convertToUTF8("\xF6", $config),
|
||||||
"\xC3\xB6"
|
"\xC3\xB6"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$config->set('Test', 'ForceNoIconv', true);
|
||||||
|
|
||||||
|
$this->assertIdentical(
|
||||||
|
$this->Encoder->convertToUTF8("\xF6", $config),
|
||||||
|
"\xC3\xB6"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_convertFromUTF8() {
|
function test_convertFromUTF8() {
|
||||||
@ -64,6 +72,14 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
$this->Encoder->convertFromUTF8("\xC3\xB6", $config),
|
$this->Encoder->convertFromUTF8("\xC3\xB6", $config),
|
||||||
"\xF6"
|
"\xF6"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$config->set('Test', 'ForceNoIconv', true);
|
||||||
|
|
||||||
|
$this->assertIdentical(
|
||||||
|
$this->Encoder->convertFromUTF8("\xC3\xB6", $config),
|
||||||
|
"\xF6"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user