mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-04 21:28:06 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
374736ae44 | ||
|
0c4a9c0479 | ||
|
06e8b022a4 | ||
|
81a03bd16c | ||
|
5770001006 | ||
|
55974e5964 | ||
|
e789bc69eb |
4
Doxyfile
4
Doxyfile
@@ -3,8 +3,8 @@
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Project related configuration options
|
# Project related configuration options
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
PROJECT_NAME = HTMLPurifier
|
PROJECT_NAME = HTML Purifier
|
||||||
PROJECT_NUMBER = trunk
|
PROJECT_NUMBER = 1.0.0
|
||||||
OUTPUT_DIRECTORY = "C:/Documents and Settings/Edward/My Documents/My Webs/htmlpurifier/docs/doxygen"
|
OUTPUT_DIRECTORY = "C:/Documents and Settings/Edward/My Documents/My Webs/htmlpurifier/docs/doxygen"
|
||||||
CREATE_SUBDIRS = NO
|
CREATE_SUBDIRS = NO
|
||||||
OUTPUT_LANGUAGE = English
|
OUTPUT_LANGUAGE = English
|
||||||
|
2
INSTALL
2
INSTALL
@@ -17,7 +17,7 @@ these versions:
|
|||||||
- 4.3.9, 4.3.11
|
- 4.3.9, 4.3.11
|
||||||
- 4.4.0, 4.4.4
|
- 4.4.0, 4.4.4
|
||||||
- 5.0.0, 5.0.4
|
- 5.0.0, 5.0.4
|
||||||
- 5.1.0, 5.1.5
|
- 5.1.0, 5.1.6
|
||||||
|
|
||||||
And can confidently say that HTML Purifier should work in all versions
|
And can confidently say that HTML Purifier should work in all versions
|
||||||
between and afterwards. HTML Purifier definitely does not support PHP 4.2,
|
between and afterwards. HTML Purifier definitely does not support PHP 4.2,
|
||||||
|
7
NEWS
7
NEWS
@@ -1,6 +1,13 @@
|
|||||||
NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
|
1.0.1, unknown release date
|
||||||
|
- Fixed slight bug in DOMLex attribute parsing
|
||||||
|
- Fixed rejection of case-insensitive configuration values when there is a
|
||||||
|
set of allowed values. This manifested in %Core.Encoding.
|
||||||
|
- Fixed rejection of inline style declarations that had lots of extra
|
||||||
|
space in them. This manifested in TinyMCE.
|
||||||
|
|
||||||
1.0.0, released 2006-09-01
|
1.0.0, released 2006-09-01
|
||||||
- Fixed broken numeric entity conversion
|
- Fixed broken numeric entity conversion
|
||||||
- Malformed UTF-8 and non-SGML character detection and cleaning implemented
|
- Malformed UTF-8 and non-SGML character detection and cleaning implemented
|
||||||
|
@@ -28,6 +28,8 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
|
|||||||
if (!$declaration) continue;
|
if (!$declaration) continue;
|
||||||
if (!strpos($declaration, ':')) continue;
|
if (!strpos($declaration, ':')) continue;
|
||||||
list($property, $value) = explode(':', $declaration, 2);
|
list($property, $value) = explode(':', $declaration, 2);
|
||||||
|
$property = trim($property);
|
||||||
|
$value = trim($value);
|
||||||
if (!isset($definition->info[$property])) continue;
|
if (!isset($definition->info[$property])) continue;
|
||||||
// inefficient call, since the validator will do this again
|
// inefficient call, since the validator will do this again
|
||||||
if (strtolower(trim($value)) !== 'inherit') {
|
if (strtolower(trim($value)) !== 'inherit') {
|
||||||
|
@@ -80,6 +80,8 @@ class HTMLPurifier_Config
|
|||||||
E_USER_WARNING);
|
E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$value = $this->def->validate($value,
|
||||||
|
$this->def->info[$namespace][$key]->type);
|
||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
// resolve value alias if defined
|
// resolve value alias if defined
|
||||||
if (isset($this->def->info[$namespace][$key]->aliases[$value])) {
|
if (isset($this->def->info[$namespace][$key]->aliases[$value])) {
|
||||||
@@ -93,8 +95,6 @@ class HTMLPurifier_Config
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$value = $this->def->validate($value,
|
|
||||||
$this->def->info[$namespace][$key]->type);
|
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
trigger_error('Value is of invalid type', E_USER_WARNING);
|
trigger_error('Value is of invalid type', E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
|
@@ -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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,8 +23,19 @@ if ( !function_exists('iconv') ) {
|
|||||||
'iso-8859-1'
|
'iso-8859-1'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
HTMLPurifier_ConfigDef::defineValueAliases(
|
||||||
|
'Core', 'Encoding', array(
|
||||||
|
'iso8859-1' => 'iso-8859-1'
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
@@ -260,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -87,19 +87,20 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$attr = $node->hasAttributes() ?
|
||||||
|
$this->transformAttrToAssoc($node->attributes) :
|
||||||
|
array();
|
||||||
|
|
||||||
// We still have to make sure that the element actually IS empty
|
// We still have to make sure that the element actually IS empty
|
||||||
if (!$node->childNodes->length) {
|
if (!$node->childNodes->length) {
|
||||||
if ($collect) {
|
if ($collect) {
|
||||||
$tokens[] = $this->factory->createEmpty(
|
$tokens[] = $this->factory->createEmpty($node->tagName, $attr);
|
||||||
$node->tagName,
|
|
||||||
$this->transformAttrToAssoc($node->attributes)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($collect) { // don't wrap on first iteration
|
if ($collect) { // don't wrap on first iteration
|
||||||
$tokens[] = $this->factory->createStart(
|
$tokens[] = $this->factory->createStart(
|
||||||
$tag_name = $node->tagName, // somehow, it get's dropped
|
$tag_name = $node->tagName, // somehow, it get's dropped
|
||||||
$this->transformAttrToAssoc($node->attributes)
|
$attr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
foreach ($node->childNodes as $node) {
|
foreach ($node->childNodes as $node) {
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
[Parse Data]
|
[Parse Data]
|
||||||
;; title of all the documentation
|
;; title of all the documentation
|
||||||
;; legal values: any string
|
;; legal values: any string
|
||||||
title = HTMLPurifier API Documentation
|
title = HTML Purifier API Documentation
|
||||||
|
|
||||||
;; parse files that start with a . like .bash_profile
|
;; parse files that start with a . like .bash_profile
|
||||||
;; legal values: true, false
|
;; legal values: true, false
|
||||||
|
@@ -92,6 +92,10 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
|
|||||||
$this->assertDef('position:absolute;', false);
|
$this->assertDef('position:absolute;', false);
|
||||||
$this->assertDef('background-image:url(javascript:alert\(\));', false);
|
$this->assertDef('background-image:url(javascript:alert\(\));', false);
|
||||||
|
|
||||||
|
// airy input
|
||||||
|
$this->assertDef(' font-weight : bold; color : #ff0000',
|
||||||
|
'font-weight:bold;color:#ff0000;');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,9 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
|||||||
HTMLPurifier_ConfigDef::define(
|
HTMLPurifier_ConfigDef::define(
|
||||||
'Extension', 'Pert', 'foo', 'string', 'A string directive.'
|
'Extension', 'Pert', 'foo', 'string', 'A string directive.'
|
||||||
);
|
);
|
||||||
|
HTMLPurifier_ConfigDef::define(
|
||||||
|
'Core', 'Encoding', 'utf-8', 'istring', 'Case insensitivity!'
|
||||||
|
);
|
||||||
|
|
||||||
HTMLPurifier_ConfigDef::defineAllowedValues(
|
HTMLPurifier_ConfigDef::defineAllowedValues(
|
||||||
'Extension', 'Pert', array('foo', 'moo')
|
'Extension', 'Pert', array('foo', 'moo')
|
||||||
@@ -39,6 +42,9 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
|||||||
HTMLPurifier_ConfigDef::defineValueAliases(
|
HTMLPurifier_ConfigDef::defineValueAliases(
|
||||||
'Extension', 'Pert', array('cow' => 'moo')
|
'Extension', 'Pert', array('cow' => 'moo')
|
||||||
);
|
);
|
||||||
|
HTMLPurifier_ConfigDef::defineAllowedValues(
|
||||||
|
'Core', 'Encoding', array('utf-8', 'iso-8859-1')
|
||||||
|
);
|
||||||
|
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
|
||||||
@@ -80,6 +86,11 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
|||||||
$this->assertNoErrors();
|
$this->assertNoErrors();
|
||||||
$this->assertIdentical($config->get('Extension', 'Pert'), 'moo');
|
$this->assertIdentical($config->get('Extension', 'Pert'), 'moo');
|
||||||
|
|
||||||
|
// case-insensitive attempt to set value that is allowed
|
||||||
|
$config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||||
|
$this->assertNoErrors();
|
||||||
|
$this->assertIdentical($config->get('Core', 'Encoding'), 'iso-8859-1');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -14,8 +14,8 @@ class HTMLPurifier_EncoderTest extends UnitTestCase
|
|||||||
|
|
||||||
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);
|
$this->assertIdentical($this->Encoder->cleanUTF8($string), $expect, 'iconv: %s');
|
||||||
$this->assertIdentical($this->Encoder->cleanUTF8($string, true), $expect);
|
$this->assertIdentical($this->Encoder->cleanUTF8($string, true), $expect, 'PHP: %s');
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_cleanUTF8() {
|
function test_cleanUTF8() {
|
||||||
@@ -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"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
24
tests/HTMLPurifier/Test.php
Normal file
24
tests/HTMLPurifier/Test.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier.php';
|
||||||
|
|
||||||
|
// integration test
|
||||||
|
|
||||||
|
class HTMLPurifier_Test extends UnitTestCase
|
||||||
|
{
|
||||||
|
var $purifier;
|
||||||
|
|
||||||
|
function assertPurification($input, $expect = null) {
|
||||||
|
if ($expect === null) $expect = $input;
|
||||||
|
$result = $this->purifier->purify($input);
|
||||||
|
$this->assertIdentical($expect, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$this->purifier = new HTMLPurifier($config);
|
||||||
|
$this->assertPurification("Null byte\0", "Null byte");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -88,6 +88,7 @@ $test_files[] = 'URISchemeRegistryTest.php';
|
|||||||
$test_files[] = 'URISchemeTest.php';
|
$test_files[] = 'URISchemeTest.php';
|
||||||
$test_files[] = 'EncoderTest.php';
|
$test_files[] = 'EncoderTest.php';
|
||||||
$test_files[] = 'EntityParserTest.php';
|
$test_files[] = 'EntityParserTest.php';
|
||||||
|
$test_files[] = 'Test.php';
|
||||||
|
|
||||||
if (version_compare(PHP_VERSION, '5', '>=')) {
|
if (version_compare(PHP_VERSION, '5', '>=')) {
|
||||||
$test_files[] = 'TokenFactoryTest.php';
|
$test_files[] = 'TokenFactoryTest.php';
|
||||||
|
Reference in New Issue
Block a user