0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

[1.7.0] HTML Purifier now works with PHP 4.3.2. Yay!

- Armor some character index checking
- Add compatibility stuff for PHP_EOL
- Add autoclose for colgroup
- Compensate for realpath() quirkiness in old versions
- Add flush maintenance script

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1096 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-05-27 14:27:54 +00:00
parent 21ab12a6a8
commit de23201cbb
10 changed files with 68 additions and 6 deletions

View File

@ -13,7 +13,7 @@ Todo: Convert to using the array syntax for configuration.
1. Compatibility 1. Compatibility
HTML Purifier works in both PHP 4 and PHP 5, from PHP 4.3.9 and up. It has no HTML Purifier works in both PHP 4 and PHP 5, from PHP 4.3.2 and up. It has no
core dependencies with other libraries. (Whoopee!) core dependencies with other libraries. (Whoopee!)
Optional extensions are iconv (usually installed) and tidy (also common). Optional extensions are iconv (usually installed) and tidy (also common).

View File

@ -17,7 +17,7 @@ ce document pour quelques choses.
1. Compatibilité 1. Compatibilité
HTML Purifier fonctionne dans PHP 4 et PHP 5. PHP 4.3.9 est le dernier HTML Purifier fonctionne dans PHP 4 et PHP 5. PHP 4.3.2 est le dernier
version que je le testais. Il ne dépend de les autre librairies. version que je le testais. Il ne dépend de les autre librairies.
Les extensions optionnel est iconv (en général déjà installer) et Les extensions optionnel est iconv (en général déjà installer) et

1
NEWS
View File

@ -20,6 +20,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
off, but it's not recommended. off, but it's not recommended.
# New compact syntax for AttrDef objects that can be used to instantiate # New compact syntax for AttrDef objects that can be used to instantiate
new objects via make() new objects via make()
! HTML Purifier now works in PHP 4.3.2.
- Deprecated and removed EnableRedundantUTF8Cleaning. It didn't even work! - Deprecated and removed EnableRedundantUTF8Cleaning. It didn't even work!
. Unit test for ElementDef created, ElementDef behavior modified to . Unit test for ElementDef created, ElementDef behavior modified to
be more flexible be more flexible

View File

@ -29,7 +29,7 @@ class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
if ($uri_string[$new_length] != ')') return false; if ($uri_string[$new_length] != ')') return false;
$uri = trim(substr($uri_string, 0, $new_length)); $uri = trim(substr($uri_string, 0, $new_length));
if (isset($uri[0]) && ($uri[0] == "'" || $uri[0] == '"')) { if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) {
$quote = $uri[0]; $quote = $uri[0];
$new_length = strlen($uri) - 1; $new_length = strlen($uri) - 1;
if ($uri[$new_length] !== $quote) return false; if ($uri[$new_length] !== $quote) return false;

View File

@ -8,6 +8,21 @@ require_once 'HTMLPurifier/CSSDefinition.php';
require_once 'HTMLPurifier/Doctype.php'; require_once 'HTMLPurifier/Doctype.php';
require_once 'HTMLPurifier/DefinitionCache.php'; require_once 'HTMLPurifier/DefinitionCache.php';
// accomodations for versions earlier than 4.3.10 and 5.0.2
// borrowed from PHP_Compat, LGPL licensed, by Aidan Lister <aidan@php.net>
if (!defined('PHP_EOL')) {
switch (strtoupper(substr(PHP_OS, 0, 3))) {
case 'WIN':
define('PHP_EOL', "\r\n");
break;
case 'DAR':
define('PHP_EOL', "\r");
break;
default:
define('PHP_EOL', "\n");
}
}
/** /**
* Configuration object that triggers customizable behavior. * Configuration object that triggers customizable behavior.
* *

View File

@ -56,7 +56,10 @@ class HTMLPurifier_HTMLModule_Tables extends HTMLPurifier_HTMLModule
$cell_align $cell_align
); );
$this->addElement('col', true, false, 'Empty', 'Common', $cell_col); $this->addElement('col', true, false, 'Empty', 'Common', $cell_col);
$this->addElement('colgroup', true, false, 'Optional: col', 'Common', $cell_col); $colgroup =& $this->addElement('colgroup', true, false, 'Optional: col', 'Common', $cell_col);
$colgroup->auto_close = $this->makeLookup(
'thead', 'tbody', 'tfoot', 'tr'
);
$this->addElement('tbody', true, false, 'Required: tr', 'Common', $cell_align); $this->addElement('tbody', true, false, 'Required: tr', 'Common', $cell_align);
$this->addElement('thead', true, false, 'Required: tr', 'Common', $cell_align); $this->addElement('thead', true, false, 'Required: tr', 'Common', $cell_align);

View File

@ -0,0 +1,22 @@
#!/usr/bin/php
<?php
/**
* Flushes the HTMLDefinition serial cache
*/
if (php_sapi_name() != 'cli') {
echo 'Script cannot be called from web-browser.';
exit;
}
echo 'Flushing cache... ';
require_once(dirname(__FILE__) . '/../library/HTMLPurifier.auto.php');
$cache = new HTMLPurifier_DefinitionCache_Serializer('HTML');
$cache->flush();
echo 'Cache flushed successfully.';
?>

View File

@ -59,7 +59,7 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends UnitTestCase
'/../../../library/HTMLPurifier/DefinitionCache/Serializer/Test/' . '/../../../library/HTMLPurifier/DefinitionCache/Serializer/Test/' .
$config_md5 . '.ser' $config_md5 . '.ser'
); );
if($file) unlink($file); // prevent previous failures from causing problems if($file && file_exists($file)) unlink($file); // prevent previous failures from causing problems
$config = $this->generateConfigMock($config_array); $config = $this->generateConfigMock($config_array);
$this->assertIdentical($config_md5, $cache->generateKey($config)); $this->assertIdentical($config_md5, $cache->generateKey($config));

View File

@ -57,7 +57,8 @@ class HTMLPurifier_EntityParserTest extends UnitTestCase
// this is only for PHP 5, the below is PHP 5 and PHP 4 // this is only for PHP 5, the below is PHP 5 and PHP 4
//$chars = str_split($arg[1], 2); //$chars = str_split($arg[1], 2);
$chars = array(); $chars = array();
for ($i = 0; isset($arg[1][$i]); $i += 2) { // strlen must be called in loop because strings size changes
for ($i = 0; strlen($arg[1]) > $i; $i += 2) {
$chars[] = $arg[1][$i] . $arg[1][$i+1]; $chars[] = $arg[1][$i] . $arg[1][$i+1];
} }
foreach ($chars as $char) { foreach ($chars as $char) {

View File

@ -97,6 +97,26 @@ class HTMLPurifier_Test extends UnitTestCase
} }
function test_table() {
$this->purifier = new HTMLPurifier();
$this->assertPurification(
'<TABLE>
<COLGROUP>
<COL span=3 width=64 />
<TBODY><TR><TD>1</TD><TD>2</TD><TD>3</TD></TR>
</TBODY>
</TABLE>',
'<table>
<colgroup>
<col span="3" width="64" />
</colgroup><tbody><tr><td>1</td><td>2</td><td>3</td></tr>
</tbody>
</table>'
);
}
} }
?> ?>