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 @@
+ Whether or not to normalize newlines to the operating
+ system default. When false
, HTML Purifier
+ will attempt to preserve mixed newline files.
+
- 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); }