Skip to content

Commit

Permalink
Rename newline normalization directive to something better.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Sep 15, 2010
1 parent 9573f09 commit 86990a2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 25 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
to utilize full-screen mode.
! Add optional support for the <code>file</code> 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.
Expand Down
15 changes: 9 additions & 6 deletions configdoc/usage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@
<line>87</line>
</file>
</directive>
<directive id="Output.Newline">
<directive id="Core.NormalizeNewlines">
<file name="HTMLPurifier/Generator.php">
<line>101</line>
</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 id="HTML.BlockWrapper">
<file name="HTMLPurifier/HTMLDefinition.php">
Expand Down Expand Up @@ -214,11 +222,6 @@
<line>48</line>
</file>
</directive>
<directive id="HTML.NewlineNormalization">
<file name="HTMLPurifier/Lexer.php">
<line>266</line>
</file>
</directive>
<directive id="Core.ConvertDocumentToFragment">
<file name="HTMLPurifier/Lexer.php">
<line>282</line>
Expand Down
Binary file modified library/HTMLPurifier/ConfigSchema/schema.ser
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

8 changes: 5 additions & 3 deletions library/HTMLPurifier/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ public function generateFromTokens($tokens) {
}

// 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;
}

Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected static function CDATACallback($matches) {
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);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/HTMLPurifier/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,18 +726,18 @@ function test_tokenizeHTML_removeProcessingInstruction() {
}

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);
}
Expand Down

0 comments on commit 86990a2

Please sign in to comment.