0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 15:28:40 +00:00

Rename newline normalization directive to something better.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Edward Z. Yang 2010-09-15 02:49:24 -04:00
parent 9573f0933d
commit 86990a21f1
8 changed files with 34 additions and 25 deletions

2
NEWS
View File

@ -20,6 +20,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
to utilize full-screen mode. to utilize full-screen mode.
! Add optional support for the <code>file</code> URI scheme, enable ! Add optional support for the <code>file</code> URI scheme, enable
by explicitly setting %URI.AllowedSchemes. by explicitly setting %URI.AllowedSchemes.
! Add %Core.NormalizeNewlines options to allow turning off newline
normalization.
- Fix improper handling of Internet Explorer conditional comments - Fix improper handling of Internet Explorer conditional comments
by parser. Thanks zmonteca for reporting. by parser. Thanks zmonteca for reporting.
- Fix missing attributes bug when running on Mac Snow Leopard and APC. - Fix missing attributes bug when running on Mac Snow Leopard and APC.

View File

@ -109,10 +109,18 @@
<line>87</line> <line>87</line>
</file> </file>
</directive> </directive>
<directive id="Output.Newline"> <directive id="Core.NormalizeNewlines">
<file name="HTMLPurifier/Generator.php"> <file name="HTMLPurifier/Generator.php">
<line>101</line> <line>101</line>
</file> </file>
<file name="HTMLPurifier/Lexer.php">
<line>266</line>
</file>
</directive>
<directive id="Output.Newline">
<file name="HTMLPurifier/Generator.php">
<line>102</line>
</file>
</directive> </directive>
<directive id="HTML.BlockWrapper"> <directive id="HTML.BlockWrapper">
<file name="HTMLPurifier/HTMLDefinition.php"> <file name="HTMLPurifier/HTMLDefinition.php">
@ -214,11 +222,6 @@
<line>48</line> <line>48</line>
</file> </file>
</directive> </directive>
<directive id="HTML.NewlineNormalization">
<file name="HTMLPurifier/Lexer.php">
<line>266</line>
</file>
</directive>
<directive id="Core.ConvertDocumentToFragment"> <directive id="Core.ConvertDocumentToFragment">
<file name="HTMLPurifier/Lexer.php"> <file name="HTMLPurifier/Lexer.php">
<line>282</line> <line>282</line>

View File

@ -0,0 +1,11 @@
Core.NormalizeNewlines
TYPE: bool
VERSION: 4.2.0
DEFAULT: true
--DESCRIPTION--
<p>
Whether or not to normalize newlines to the operating
system default. When <code>false</code>, HTML Purifier
will attempt to preserve mixed newline files.
</p>
--# vim: et sw=4 sts=4

View File

@ -1,9 +0,0 @@
HTML.NewlineNormalization
TYPE: bool
VERSION: 4.2.0
DEFAULT: true
--DESCRIPTION--
<p>
Whether or not to normalize newlines.
</p>
--# vim: et sw=4 sts=4

View File

@ -98,9 +98,11 @@ class HTMLPurifier_Generator
} }
// Normalize newlines to system defined value // Normalize newlines to system defined value
$nl = $this->config->get('Output.Newline'); if ($this->config->get('Core.NormalizeNewlines')) {
if ($nl === null) $nl = PHP_EOL; $nl = $this->config->get('Output.Newline');
if ($nl !== "\n") $html = str_replace("\n", $nl, $html); if ($nl === null) $nl = PHP_EOL;
if ($nl !== "\n") $html = str_replace("\n", $nl, $html);
}
return $html; return $html;
} }

View File

@ -263,7 +263,7 @@ class HTMLPurifier_Lexer
public function normalize($html, $config, $context) { public function normalize($html, $config, $context) {
// normalize newlines to \n // 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", "\n", $html);
$html = str_replace("\r", "\n", $html); $html = str_replace("\r", "\n", $html);
} }

View File

@ -726,18 +726,18 @@ div {}
} }
function test_tokenizeHTML_removeNewline() { function test_tokenizeHTML_removeNewline() {
$this->config->set('HTML.NewlineNormalization', true); $this->config->set('Core.NormalizeNewlines', true);
$input = "plain text\r\n"; $input = "plain\rtext\r\n";
$expect = array( $expect = array(
new HTMLPurifier_Token_Text("plain text\n") new HTMLPurifier_Token_Text("plain\ntext\n")
); );
} }
function test_tokenizeHTML_noRemoveNewline() { function test_tokenizeHTML_noRemoveNewline() {
$this->config->set('HTML.NewlineNormalization', false); $this->config->set('Core.NormalizeNewlines', false);
$input = "plain text\r\n"; $input = "plain\rtext\r\n";
$expect = array( $expect = array(
new HTMLPurifier_Token_Text("plain text\r\n") new HTMLPurifier_Token_Text("plain\rtext\r\n")
); );
$this->assertTokenization($input, $expect); $this->assertTokenization($input, $expect);
} }