From 86990a21f1c572687dc486b33a6c4e8a999f5854 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 15 Sep 2010 02:49:24 -0400 Subject: [PATCH] Rename newline normalization directive to something better. Signed-off-by: Edward Z. Yang --- NEWS | 2 ++ configdoc/usage.xml | 15 +++++++++------ library/HTMLPurifier/ConfigSchema/schema.ser | Bin 13710 -> 13701 bytes .../ConfigSchema/schema/Core.NormalizeNewlines.txt | 11 +++++++++++ .../schema/HTML.NewlineNormalization.txt | 9 --------- library/HTMLPurifier/Generator.php | 8 +++++--- library/HTMLPurifier/Lexer.php | 2 +- tests/HTMLPurifier/LexerTest.php | 12 ++++++------ 8 files changed, 34 insertions(+), 25 deletions(-) rewrite library/HTMLPurifier/ConfigSchema/schema.ser (83%) create mode 100644 library/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt delete mode 100644 library/HTMLPurifier/ConfigSchema/schema/HTML.NewlineNormalization.txt diff --git a/NEWS b/NEWS index 2b7fe3fb..769d786d 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier to utilize full-screen mode. ! Add optional support for the file URI scheme, enable by explicitly setting %URI.AllowedSchemes. +! Add %Core.NormalizeNewlines options to allow turning off newline + normalization. - Fix improper handling of Internet Explorer conditional comments by parser. Thanks zmonteca for reporting. - Fix missing attributes bug when running on Mac Snow Leopard and APC. diff --git a/configdoc/usage.xml b/configdoc/usage.xml index b0944479..bd2f1a8a 100644 --- a/configdoc/usage.xml +++ b/configdoc/usage.xml @@ -109,10 +109,18 @@ 87 - + 101 + + 266 + + + + + 102 + @@ -214,11 +222,6 @@ 48 - - - 266 - - 282 diff --git a/library/HTMLPurifier/ConfigSchema/schema.ser b/library/HTMLPurifier/ConfigSchema/schema.ser dissimilarity index 83% index 528bd0de0ec7e766f2c923f2a55b7d01c6713e6e..978089c6291e7d828f6233ac632cedd8a98fdfd7 100644 GIT binary patch delta 134 zcwXzvZq44XibKxGO369DC{@odzbH2`C$lQmFSR@;GcUDR$vVl(aI=QwLFUbTvQL>e c7YghqR&^YYEFOiKR-4l`r?72SFvw#C0DWpMasU7T delta 151 zcwTGG?#te=ievK`j=juEMy6Iu9wELydVZe)&bYi8+~7i6xo&c}mtvR)(9~ lcoy@Jp!fyz=C=x!9Fxy*NNrxES;|I8SEiNuW)XuzRsd)NHZ%YL diff --git a/library/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt b/library/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt new file mode 100644 index 00000000..d77f5360 --- /dev/null +++ b/library/HTMLPurifier/ConfigSchema/schema/Core.NormalizeNewlines.txt @@ -0,0 +1,11 @@ +Core.NormalizeNewlines +TYPE: bool +VERSION: 4.2.0 +DEFAULT: true +--DESCRIPTION-- +

+ Whether or not to normalize newlines to the operating + system default. When false, HTML Purifier + will attempt to preserve mixed newline files. +

+--# vim: et sw=4 sts=4 diff --git a/library/HTMLPurifier/ConfigSchema/schema/HTML.NewlineNormalization.txt b/library/HTMLPurifier/ConfigSchema/schema/HTML.NewlineNormalization.txt deleted file mode 100644 index 948aea89..00000000 --- a/library/HTMLPurifier/ConfigSchema/schema/HTML.NewlineNormalization.txt +++ /dev/null @@ -1,9 +0,0 @@ -HTML.NewlineNormalization -TYPE: bool -VERSION: 4.2.0 -DEFAULT: true ---DESCRIPTION-- -

- Whether or not to normalize newlines. -

---# vim: et sw=4 sts=4 diff --git a/library/HTMLPurifier/Generator.php b/library/HTMLPurifier/Generator.php index f5310361..e6221db7 100644 --- a/library/HTMLPurifier/Generator.php +++ b/library/HTMLPurifier/Generator.php @@ -98,9 +98,11 @@ class HTMLPurifier_Generator } // Normalize newlines to system defined value - $nl = $this->config->get('Output.Newline'); - if ($nl === null) $nl = PHP_EOL; - if ($nl !== "\n") $html = str_replace("\n", $nl, $html); + if ($this->config->get('Core.NormalizeNewlines')) { + $nl = $this->config->get('Output.Newline'); + if ($nl === null) $nl = PHP_EOL; + if ($nl !== "\n") $html = str_replace("\n", $nl, $html); + } return $html; } diff --git a/library/HTMLPurifier/Lexer.php b/library/HTMLPurifier/Lexer.php index db14ebac..325d5c5f 100644 --- a/library/HTMLPurifier/Lexer.php +++ b/library/HTMLPurifier/Lexer.php @@ -263,7 +263,7 @@ class HTMLPurifier_Lexer public function normalize($html, $config, $context) { // normalize newlines to \n - if ($config->get('HTML.NewlineNormalization')) { + if ($config->get('Core.NormalizeNewlines')) { $html = str_replace("\r\n", "\n", $html); $html = str_replace("\r", "\n", $html); } diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index 79d1cf87..da582d15 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -726,18 +726,18 @@ div {} } function test_tokenizeHTML_removeNewline() { - $this->config->set('HTML.NewlineNormalization', true); - $input = "plain text\r\n"; + $this->config->set('Core.NormalizeNewlines', true); + $input = "plain\rtext\r\n"; $expect = array( - new HTMLPurifier_Token_Text("plain text\n") + new HTMLPurifier_Token_Text("plain\ntext\n") ); } function test_tokenizeHTML_noRemoveNewline() { - $this->config->set('HTML.NewlineNormalization', false); - $input = "plain text\r\n"; + $this->config->set('Core.NormalizeNewlines', false); + $input = "plain\rtext\r\n"; $expect = array( - new HTMLPurifier_Token_Text("plain text\r\n") + new HTMLPurifier_Token_Text("plain\rtext\r\n") ); $this->assertTokenization($input, $expect); } -- 2.11.4.GIT