0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Make newline normalization optional.

This commit is contained in:
Tomasz Muras 2010-09-10 21:51:55 +01:00 committed by Edward Z. Yang
parent 632bf2bbd4
commit 9573f0933d
8 changed files with 42 additions and 8 deletions

View File

@ -6,7 +6,7 @@
</file>
<file name="HTMLPurifier/Lexer.php">
<line>81</line>
<line>282</line>
<line>284</line>
</file>
<file name="HTMLPurifier/Lexer/DirectLex.php">
<line>53</line>
@ -154,7 +154,7 @@
<line>202</line>
</file>
<file name="HTMLPurifier/Lexer.php">
<line>269</line>
<line>271</line>
</file>
<file name="HTMLPurifier/HTMLModule/Image.php">
<line>27</line>
@ -214,14 +214,19 @@
<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>280</line>
<line>282</line>
</file>
</directive>
<directive id="Core.RemoveProcessingInstructions">
<file name="HTMLPurifier/Lexer.php">
<line>301</line>
<line>303</line>
</file>
</directive>
<directive id="URI.">

View File

@ -201,6 +201,7 @@ require 'HTMLPurifier/URIFilter/HostBlacklist.php';
require 'HTMLPurifier/URIFilter/MakeAbsolute.php';
require 'HTMLPurifier/URIFilter/Munge.php';
require 'HTMLPurifier/URIScheme/data.php';
require 'HTMLPurifier/URIScheme/file.php';
require 'HTMLPurifier/URIScheme/ftp.php';
require 'HTMLPurifier/URIScheme/http.php';
require 'HTMLPurifier/URIScheme/https.php';

View File

@ -195,6 +195,7 @@ require_once $__dir . '/HTMLPurifier/URIFilter/HostBlacklist.php';
require_once $__dir . '/HTMLPurifier/URIFilter/MakeAbsolute.php';
require_once $__dir . '/HTMLPurifier/URIFilter/Munge.php';
require_once $__dir . '/HTMLPurifier/URIScheme/data.php';
require_once $__dir . '/HTMLPurifier/URIScheme/file.php';
require_once $__dir . '/HTMLPurifier/URIScheme/ftp.php';
require_once $__dir . '/HTMLPurifier/URIScheme/http.php';
require_once $__dir . '/HTMLPurifier/URIScheme/https.php';

View File

@ -0,0 +1,9 @@
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

@ -263,8 +263,10 @@ class HTMLPurifier_Lexer
public function normalize($html, $config, $context) {
// normalize newlines to \n
$html = str_replace("\r\n", "\n", $html);
$html = str_replace("\r", "\n", $html);
if ($config->get('HTML.NewlineNormalization')) {
$html = str_replace("\r\n", "\n", $html);
$html = str_replace("\r", "\n", $html);
}
if ($config->get('HTML.Trusted')) {
// escape convoluted CDATA

View File

@ -125,8 +125,6 @@ class HTML5 {
const EOF = 5;
public function __construct($data) {
$data = str_replace("\r\n", "\n", $data);
$data = str_replace("\r", null, $data);
$this->data = $data;
$this->char = -1;

View File

@ -725,6 +725,24 @@ div {}
);
}
function test_tokenizeHTML_removeNewline() {
$this->config->set('HTML.NewlineNormalization', true);
$input = "plain text\r\n";
$expect = array(
new HTMLPurifier_Token_Text("plain text\n")
);
}
function test_tokenizeHTML_noRemoveNewline() {
$this->config->set('HTML.NewlineNormalization', false);
$input = "plain text\r\n";
$expect = array(
new HTMLPurifier_Token_Text("plain text\r\n")
);
$this->assertTokenization($input, $expect);
}
/*
function test_tokenizeHTML_() {