diff --git a/NEWS b/NEWS index 9a56421b..5c5272c4 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,11 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier had both namespace and directive now have a single unified key. # Some configuration directives were renamed, specifically: %AutoFormatParam.PurifierLinkifyDocURL -> %AutoFormat.PurifierLinkify.DocURL + %FilterParam.ExtractStyleBlocksEscaping -> %Filter.ExtractStyleBlocks.Escaping + %FilterParam.ExtractStyleBlocksScope -> %Filter.ExtractStyleBlocks.Scope + %FilterParam.ExtractStyleBlocksTidyImpl -> %Filter.ExtractStyleBlocks.TidyImpl + As usual, the old directive names will still work, but will through E_NOTICE + errors. ! More robust support for name="" and id="" ! HTMLPurifier_Config::inherit($config) allows you to inherit one configuration, and have changes to that configuration be propagated @@ -26,6 +31,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier tags that contain non-breaking spaces as well other whitespace. You can also modify which tags should have maintained with %AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions. +. Created script maintenance/rename-config.php for renaming a configuration + directive while maintaining its alias. This script does not change source code. 3.3.0, released 2009-02-16 ! Implement CSS property 'overflow' when %CSS.AllowTricky is true. diff --git a/library/HTMLPurifier.php b/library/HTMLPurifier.php index 64ae1487..27d0e726 100644 --- a/library/HTMLPurifier.php +++ b/library/HTMLPurifier.php @@ -152,6 +152,7 @@ class HTMLPurifier $filters = array(); foreach ($filter_flags as $filter => $flag) { if (!$flag) continue; + if (strpos($filter, '.') !== false) continue; $class = "HTMLPurifier_Filter_$filter"; $filters[] = new $class; } diff --git a/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php b/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php index e1a9a81c..d7df56ae 100644 --- a/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php +++ b/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php @@ -13,7 +13,6 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder } public static function buildFromDirectory($dir = null) { - $parser = new HTMLPurifier_StringHashParser(); $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder(); $interchange = new HTMLPurifier_ConfigSchema_Interchange(); @@ -33,15 +32,20 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder sort($files); foreach ($files as $file) { - $builder->build( - $interchange, - new HTMLPurifier_StringHash( $parser->parseFile($dir . $file) ) - ); + $builder->buildFile($interchange, $dir . $file); } return $interchange; } + public function buildFile($interchange, $file) { + $parser = new HTMLPurifier_StringHashParser(); + $this->build( + $interchange, + new HTMLPurifier_StringHash( $parser->parseFile($dir . $file) ) + ); + } + /** * Builds an interchange object based on a hash. * @param $interchange HTMLPurifier_ConfigSchema_Interchange object to build diff --git a/library/HTMLPurifier/ConfigSchema/schema.ser b/library/HTMLPurifier/ConfigSchema/schema.ser index 5dc9a5ac..81185b58 100644 Binary files a/library/HTMLPurifier/ConfigSchema/schema.ser and b/library/HTMLPurifier/ConfigSchema/schema.ser differ diff --git a/library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksEscaping.txt b/library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt similarity index 75% rename from library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksEscaping.txt rename to library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt index d436ed01..16829bcd 100644 --- a/library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksEscaping.txt +++ b/library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Escaping.txt @@ -1,8 +1,8 @@ -FilterParam.ExtractStyleBlocksEscaping +Filter.ExtractStyleBlocks.Escaping TYPE: bool VERSION: 3.0.0 DEFAULT: true -ALIASES: Filter.ExtractStyleBlocksEscaping +ALIASES: Filter.ExtractStyleBlocksEscaping, FilterParam.ExtractStyleBlocksEscaping --DESCRIPTION--
diff --git a/library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksScope.txt b/library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt similarity index 90% rename from library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksScope.txt rename to library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt index 3943529c..7f95f54d 100644 --- a/library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksScope.txt +++ b/library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.Scope.txt @@ -1,8 +1,8 @@ -FilterParam.ExtractStyleBlocksScope +Filter.ExtractStyleBlocks.Scope TYPE: string/null VERSION: 3.0.0 DEFAULT: NULL -ALIASES: Filter.ExtractStyleBlocksScope +ALIASES: Filter.ExtractStyleBlocksScope, FilterParam.ExtractStyleBlocksScope --DESCRIPTION--
diff --git a/library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksTidyImpl.txt b/library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt similarity index 85% rename from library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksTidyImpl.txt rename to library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt index cafccf8b..6c231b2d 100644 --- a/library/HTMLPurifier/ConfigSchema/schema/FilterParam.ExtractStyleBlocksTidyImpl.txt +++ b/library/HTMLPurifier/ConfigSchema/schema/Filter.ExtractStyleBlocks.TidyImpl.txt @@ -1,7 +1,8 @@ -FilterParam.ExtractStyleBlocksTidyImpl +Filter.ExtractStyleBlocks.TidyImpl TYPE: mixed/null VERSION: 3.1.0 DEFAULT: NULL +ALIASES: FilterParam.ExtractStyleBlocksTidyImpl --DESCRIPTION--
If left NULL, HTML Purifier will attempt to instantiate a csstidy
diff --git a/library/HTMLPurifier/Filter/ExtractStyleBlocks.php b/library/HTMLPurifier/Filter/ExtractStyleBlocks.php
index 94dd598d..bbf78a66 100644
--- a/library/HTMLPurifier/Filter/ExtractStyleBlocks.php
+++ b/library/HTMLPurifier/Filter/ExtractStyleBlocks.php
@@ -38,7 +38,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
* @todo Extend to indicate non-text/css style blocks
*/
public function preFilter($html, $config, $context) {
- $tidy = $config->get('FilterParam.ExtractStyleBlocksTidyImpl');
+ $tidy = $config->get('Filter.ExtractStyleBlocks.TidyImpl');
if ($tidy !== null) $this->_tidy = $tidy;
$html = preg_replace_callback('##isU', array($this, 'styleCallback'), $html);
$style_blocks = $this->_styleMatches;
@@ -62,7 +62,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
*/
public function cleanCSS($css, $config, $context) {
// prepare scope
- $scope = $config->get('FilterParam.ExtractStyleBlocksScope');
+ $scope = $config->get('Filter.ExtractStyleBlocks.Scope');
if ($scope !== null) {
$scopes = array_map('trim', explode(',', $scope));
} else {
@@ -120,7 +120,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
$css = $this->_tidy->print->plain();
// we are going to escape any special characters <>& to ensure
// that no funny business occurs (i.e. in a font-family prop).
- if ($config->get('FilterParam.ExtractStyleBlocksEscaping')) {
+ if ($config->get('Filter.ExtractStyleBlocks.Escaping')) {
$css = str_replace(
array('<', '>', '&'),
array('\3C ', '\3E ', '\26 '),
diff --git a/maintenance/rename-config.php b/maintenance/rename-config.php
new file mode 100644
index 00000000..6e59e2a7
--- /dev/null
+++ b/maintenance/rename-config.php
@@ -0,0 +1,84 @@
+#!/usr/bin/php
+buildFile($interchange, $file);
+$contents = file_get_contents($file);
+
+if (strpos($contents, "\r\n") !== false) {
+ $nl = "\r\n";
+} elseif (strpos($contents, "\r") !== false) {
+ $nl = "\r";
+} else {
+ $nl = "\n";
+}
+
+// replace name with new name
+$contents = str_replace($old, $new, $contents);
+
+if ($interchange->directives[$old]->aliases) {
+ $pos_alias = strpos($contents, 'ALIASES:');
+ $pos_ins = strpos($contents, $nl, $pos_alias);
+ if ($pos_ins === false) $pos_ins = strlen($contents);
+ $contents =
+ substr($contents, 0, $pos_ins) . ", $old" . substr($contents, $pos_ins);
+ file_put_contents($file, $contents);
+} else {
+ $lines = explode($nl, $contents);
+ $insert = false;
+ foreach ($lines as $n => $line) {
+ if (strncmp($line, '--', 2) === 0) {
+ $insert = $n;
+ break;
+ }
+ }
+ if (!$insert) {
+ $lines[] = "ALIASES: $old";
+ } else {
+ array_splice($lines, $insert, 0, "ALIASES: $old");
+ }
+ file_put_contents($file, implode($nl, $lines));
+}
+
+rename("$old.txt", "$new.txt") || exit(1);
diff --git a/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php b/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php
index 51499c60..9c26d4c9 100644
--- a/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php
+++ b/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php
@@ -23,7 +23,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
function assertExtractStyleBlocks($html, $expect = true, $styles = array()) {
$filter = new HTMLPurifier_Filter_ExtractStyleBlocks(); // disable cleaning
if ($expect === true) $expect = $html;
- $this->config->set('FilterParam.ExtractStyleBlocksTidyImpl', false);
+ $this->config->set('Filter.ExtractStyleBlocks.TidyImpl', false);
$result = $filter->preFilter($html, $this->config, $this->context);
$this->assertIdentical($result, $expect);
$this->assertIdentical($this->context->get('StyleBlocks'), $styles);
@@ -104,14 +104,14 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
}
function test_cleanCSS_noEscapeCodes() {
- $this->config->set('FilterParam.ExtractStyleBlocksEscaping', false);
+ $this->config->set('Filter.ExtractStyleBlocks.Escaping', false);
$this->assertCleanCSS(
".class {\nfont-family:'';\n}"
);
}
function test_cleanCSS_scope() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(
"p {\ntext-indent:1em;\n}",
"#foo p {\ntext-indent:1em;\n}"
@@ -119,7 +119,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
}
function test_cleanCSS_scopeWithSelectorCommas() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(
"b, i {\ntext-decoration:underline;\n}",
"#foo b, #foo i {\ntext-decoration:underline;\n}"
@@ -127,17 +127,17 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
}
function test_cleanCSS_scopeWithNaughtySelector() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(" + p {\ntext-indent:1em;\n}", '');
}
function test_cleanCSS_scopeWithMultipleNaughtySelectors() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(" ++ ++ p {\ntext-indent:1em;\n}", '');
}
function test_cleanCSS_scopeWithCommas() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo, .bar');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar');
$this->assertCleanCSS(
"p {\ntext-indent:1em;\n}",
"#foo p, .bar p {\ntext-indent:1em;\n}"
@@ -145,7 +145,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
}
function test_cleanCSS_scopeAllWithCommas() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo, .bar');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar');
$this->assertCleanCSS(
"p, div {\ntext-indent:1em;\n}",
"#foo p, #foo div, .bar p, .bar div {\ntext-indent:1em;\n}"
@@ -153,7 +153,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
}
function test_cleanCSS_scopeWithConflicts() {
- $this->config->set('FilterParam.ExtractStyleBlocksScope', 'p');
+ $this->config->set('Filter.ExtractStyleBlocks.Scope', 'p');
$this->assertCleanCSS(
"div {
text-align:right;