mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-06 06:31:52 +00:00
[1.4.0] Make all functions in Encoder static. Affects branches/strict
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@656 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
2816ae535f
commit
ad1169c711
@ -91,7 +91,6 @@ class HTMLPurifier
|
|||||||
$this->lexer = HTMLPurifier_Lexer::create();
|
$this->lexer = HTMLPurifier_Lexer::create();
|
||||||
$this->strategy = new HTMLPurifier_Strategy_Core();
|
$this->strategy = new HTMLPurifier_Strategy_Core();
|
||||||
$this->generator = new HTMLPurifier_Generator();
|
$this->generator = new HTMLPurifier_Generator();
|
||||||
$this->encoder = new HTMLPurifier_Encoder();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ class HTMLPurifier
|
|||||||
$config = $config ? HTMLPurifier_Config::create($config) : $this->config;
|
$config = $config ? HTMLPurifier_Config::create($config) : $this->config;
|
||||||
|
|
||||||
$context = new HTMLPurifier_Context();
|
$context = new HTMLPurifier_Context();
|
||||||
$html = $this->encoder->convertToUTF8($html, $config, $context);
|
$html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context);
|
||||||
|
|
||||||
// purified HTML
|
// purified HTML
|
||||||
$html =
|
$html =
|
||||||
@ -127,7 +126,7 @@ class HTMLPurifier
|
|||||||
$config, $context
|
$config, $context
|
||||||
);
|
);
|
||||||
|
|
||||||
$html = $this->encoder->convertFromUTF8($html, $config, $context);
|
$html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context);
|
||||||
$this->context =& $context;
|
$this->context =& $context;
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,18 @@ HTMLPurifier_ConfigSchema::define(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A UTF-8 specific character encoder that handles cleaning and transforming.
|
* A UTF-8 specific character encoder that handles cleaning and transforming.
|
||||||
|
* @note All functions in this class should be static.
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_Encoder
|
class HTMLPurifier_Encoder
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor throws fatal error if you attempt to instantiate class
|
||||||
|
*/
|
||||||
|
function HTMLPurifier_Encoder() {
|
||||||
|
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans a UTF-8 string for well-formedness and SGML validity
|
* Cleans a UTF-8 string for well-formedness and SGML validity
|
||||||
*
|
*
|
||||||
@ -290,6 +298,7 @@ class HTMLPurifier_Encoder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a string to UTF-8 based on configuration.
|
* Converts a string to UTF-8 based on configuration.
|
||||||
|
* @static
|
||||||
*/
|
*/
|
||||||
function convertToUTF8($str, $config, &$context) {
|
function convertToUTF8($str, $config, &$context) {
|
||||||
static $iconv = null;
|
static $iconv = null;
|
||||||
@ -305,6 +314,7 @@ class HTMLPurifier_Encoder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a string from UTF-8 based on configuration.
|
* Converts a string from UTF-8 based on configuration.
|
||||||
|
* @static
|
||||||
* @note Currently, this is a lossy conversion, with unexpressable
|
* @note Currently, this is a lossy conversion, with unexpressable
|
||||||
* characters being omitted.
|
* characters being omitted.
|
||||||
*/
|
*/
|
||||||
|
@ -56,7 +56,6 @@ class HTMLPurifier_Lexer
|
|||||||
{
|
{
|
||||||
|
|
||||||
function HTMLPurifier_Lexer() {
|
function HTMLPurifier_Lexer() {
|
||||||
$this->_encoder = new HTMLPurifier_Encoder();
|
|
||||||
$this->_entity_parser = new HTMLPurifier_EntityParser();
|
$this->_entity_parser = new HTMLPurifier_EntityParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +113,6 @@ class HTMLPurifier_Lexer
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $_encoder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lexes an HTML string into tokens.
|
* Lexes an HTML string into tokens.
|
||||||
*
|
*
|
||||||
@ -216,7 +213,7 @@ class HTMLPurifier_Lexer
|
|||||||
// clean into wellformed UTF-8 string for an SGML context: this has
|
// clean into wellformed UTF-8 string for an SGML context: this has
|
||||||
// to be done after entity expansion because the entities sometimes
|
// to be done after entity expansion because the entities sometimes
|
||||||
// represent non-SGML characters (horror, horror!)
|
// represent non-SGML characters (horror, horror!)
|
||||||
$html = $this->_encoder->cleanUTF8($html);
|
$html = HTMLPurifier_Encoder::cleanUTF8($html);
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,13 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
var $Encoder;
|
var $Encoder;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->Encoder = new HTMLPurifier_Encoder();
|
|
||||||
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
|
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertCleanUTF8($string, $expect = null) {
|
function assertCleanUTF8($string, $expect = null) {
|
||||||
if ($expect === null) $expect = $string;
|
if ($expect === null) $expect = $string;
|
||||||
$this->assertIdentical($this->Encoder->cleanUTF8($string), $expect, 'iconv: %s');
|
$this->assertIdentical(HTMLPurifier_Encoder::cleanUTF8($string), $expect, 'iconv: %s');
|
||||||
$this->assertIdentical($this->Encoder->cleanUTF8($string, true), $expect, 'PHP: %s');
|
$this->assertIdentical(HTMLPurifier_Encoder::cleanUTF8($string, true), $expect, 'PHP: %s');
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_cleanUTF8() {
|
function test_cleanUTF8() {
|
||||||
@ -35,7 +34,7 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
|
|
||||||
// UTF-8 means that we don't touch it
|
// UTF-8 means that we don't touch it
|
||||||
$this->assertIdentical(
|
$this->assertIdentical(
|
||||||
$this->Encoder->convertToUTF8("\xF6", $config, $context),
|
HTMLPurifier_Encoder::convertToUTF8("\xF6", $config, $context),
|
||||||
"\xF6" // this is invalid
|
"\xF6" // this is invalid
|
||||||
);
|
);
|
||||||
$this->assertNoErrors();
|
$this->assertNoErrors();
|
||||||
@ -44,14 +43,14 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
|
|
||||||
// Now it gets converted
|
// Now it gets converted
|
||||||
$this->assertIdentical(
|
$this->assertIdentical(
|
||||||
$this->Encoder->convertToUTF8("\xF6", $config, $context),
|
HTMLPurifier_Encoder::convertToUTF8("\xF6", $config, $context),
|
||||||
"\xC3\xB6"
|
"\xC3\xB6"
|
||||||
);
|
);
|
||||||
|
|
||||||
$config->set('Test', 'ForceNoIconv', true);
|
$config->set('Test', 'ForceNoIconv', true);
|
||||||
|
|
||||||
$this->assertIdentical(
|
$this->assertIdentical(
|
||||||
$this->Encoder->convertToUTF8("\xF6", $config, $context),
|
HTMLPurifier_Encoder::convertToUTF8("\xF6", $config, $context),
|
||||||
"\xC3\xB6"
|
"\xC3\xB6"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
|
|
||||||
// UTF-8 means that we don't touch it
|
// UTF-8 means that we don't touch it
|
||||||
$this->assertIdentical(
|
$this->assertIdentical(
|
||||||
$this->Encoder->convertFromUTF8("\xC3\xB6", $config, $context),
|
HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $config, $context),
|
||||||
"\xC3\xB6"
|
"\xC3\xB6"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -71,14 +70,14 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
|
|
||||||
// Now it gets converted
|
// Now it gets converted
|
||||||
$this->assertIdentical(
|
$this->assertIdentical(
|
||||||
$this->Encoder->convertFromUTF8("\xC3\xB6", $config, $context),
|
HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $config, $context),
|
||||||
"\xF6"
|
"\xF6"
|
||||||
);
|
);
|
||||||
|
|
||||||
$config->set('Test', 'ForceNoIconv', true);
|
$config->set('Test', 'ForceNoIconv', true);
|
||||||
|
|
||||||
$this->assertIdentical(
|
$this->assertIdentical(
|
||||||
$this->Encoder->convertFromUTF8("\xC3\xB6", $config, $context),
|
HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $config, $context),
|
||||||
"\xF6"
|
"\xF6"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user