1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-11 00:24:03 +02:00

Handle CRLF discrepancies

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2008-06-24 21:10:51 -04:00
parent a84b6d5be0
commit 6bb8c1fcac
99 changed files with 6183 additions and 6183 deletions

View File

@@ -1,102 +1,102 @@
--- C:\Users\Edward\Webs\htmlpurifier\maintenance\PH5P.php 2007-11-05 00:01:51.643585000 -0500
+++ C:\Users\Edward\Webs\htmlpurifier\maintenance/PH5P.new.php 2008-04-05 00:26:39.343160000 -0400
@@ -65,7 +65,7 @@
public function __construct($data) {
$data = str_replace("\r\n", "\n", $data);
- $date = str_replace("\r", null, $data);
+ $data = str_replace("\r", null, $data);
$this->data = $data;
$this->char = -1;
public function __construct($data) {
$data = str_replace("\r\n", "\n", $data);
- $date = str_replace("\r", null, $data);
+ $data = str_replace("\r", null, $data);
$this->data = $data;
$this->char = -1;
@@ -211,7 +211,10 @@
// If nothing is returned, emit a U+0026 AMPERSAND character token.
// Otherwise, emit the character token that was returned.
$char = (!$entity) ? '&' : $entity;
- $this->emitToken($char);
+ $this->emitToken(array(
+ 'type' => self::CHARACTR,
+ 'data' => $char
+ ));
// Finally, switch to the data state.
$this->state = 'data';
// If nothing is returned, emit a U+0026 AMPERSAND character token.
// Otherwise, emit the character token that was returned.
$char = (!$entity) ? '&' : $entity;
- $this->emitToken($char);
+ $this->emitToken(array(
+ 'type' => self::CHARACTR,
+ 'data' => $char
+ ));
// Finally, switch to the data state.
$this->state = 'data';
@@ -708,7 +711,7 @@
} elseif($char === '&') {
/* U+0026 AMPERSAND (&)
Switch to the entity in attribute value state. */
- $this->entityInAttributeValueState('non');
+ $this->entityInAttributeValueState();
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
} elseif($char === '&') {
/* U+0026 AMPERSAND (&)
Switch to the entity in attribute value state. */
- $this->entityInAttributeValueState('non');
+ $this->entityInAttributeValueState();
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
@@ -738,7 +741,8 @@
? '&'
: $entity;
- $this->emitToken($char);
+ $last = count($this->token['attr']) - 1;
+ $this->token['attr'][$last]['value'] .= $char;
}
private function bogusCommentState() {
? '&'
: $entity;
- $this->emitToken($char);
+ $last = count($this->token['attr']) - 1;
+ $this->token['attr'][$last]['value'] .= $char;
}
private function bogusCommentState() {
@@ -1066,6 +1070,11 @@
$this->char++;
if(in_array($id, $this->entities)) {
+ if ($e_name[$c-1] !== ';') {
+ if ($c < $len && $e_name[$c] == ';') {
+ $this->char++; // consume extra semicolon
+ }
+ }
$entity = $id;
break;
}
$this->char++;
if(in_array($id, $this->entities)) {
+ if ($e_name[$c-1] !== ';') {
+ if ($c < $len && $e_name[$c] == ';') {
+ $this->char++; // consume extra semicolon
+ }
+ }
$entity = $id;
break;
}
@@ -2084,7 +2093,7 @@
/* Reconstruct the active formatting elements, if any. */
$this->reconstructActiveFormattingElements();
- $this->insertElement($token);
+ $this->insertElement($token, true, true);
break;
}
break;
/* Reconstruct the active formatting elements, if any. */
$this->reconstructActiveFormattingElements();
- $this->insertElement($token);
+ $this->insertElement($token, true, true);
break;
}
break;
@@ -3465,7 +3474,18 @@
}
}
- private function insertElement($token, $append = true) {
+ private function insertElement($token, $append = true, $check = false) {
+ // Proprietary workaround for libxml2's limitations with tag names
+ if ($check) {
+ // Slightly modified HTML5 tag-name modification,
+ // removing anything that's not an ASCII letter, digit, or hyphen
+ $token['name'] = preg_replace('/[^a-z0-9-]/i', '', $token['name']);
+ // Remove leading hyphens and numbers
+ $token['name'] = ltrim($token['name'], '-0..9');
+ // In theory, this should ever be needed, but just in case
+ if ($token['name'] === '') $token['name'] = 'span'; // arbitrary generic choice
+ }
+
$el = $this->dom->createElement($token['name']);
foreach($token['attr'] as $attr) {
}
}
- private function insertElement($token, $append = true) {
+ private function insertElement($token, $append = true, $check = false) {
+ // Proprietary workaround for libxml2's limitations with tag names
+ if ($check) {
+ // Slightly modified HTML5 tag-name modification,
+ // removing anything that's not an ASCII letter, digit, or hyphen
+ $token['name'] = preg_replace('/[^a-z0-9-]/i', '', $token['name']);
+ // Remove leading hyphens and numbers
+ $token['name'] = ltrim($token['name'], '-0..9');
+ // In theory, this should ever be needed, but just in case
+ if ($token['name'] === '') $token['name'] = 'span'; // arbitrary generic choice
+ }
+
$el = $this->dom->createElement($token['name']);
foreach($token['attr'] as $attr) {
@@ -3659,7 +3679,7 @@
}
}
- private function generateImpliedEndTags(array $exclude = array()) {
+ private function generateImpliedEndTags($exclude = array()) {
/* When the steps below require the UA to generate implied end tags,
then, if the current node is a dd element, a dt element, an li element,
a p element, a td element, a th element, or a tr element, the UA must
}
}
- private function generateImpliedEndTags(array $exclude = array()) {
+ private function generateImpliedEndTags($exclude = array()) {
/* When the steps below require the UA to generate implied end tags,
then, if the current node is a dd element, a dt element, an li element,
a p element, a td element, a th element, or a tr element, the UA must
@@ -3673,7 +3693,8 @@
}
}
- private function getElementCategory($name) {
+ private function getElementCategory($node) {
+ $name = $node->tagName;
if(in_array($name, $this->special))
return self::SPECIAL;
}
}
- private function getElementCategory($name) {
+ private function getElementCategory($node) {
+ $name = $node->tagName;
if(in_array($name, $this->special))
return self::SPECIAL;

View File

@@ -1,8 +1,8 @@
Index: src/PHPT/Case.php
===================================================================
--- src/PHPT/Case.php (revision 691)
+++ src/PHPT/Case.php (working copy)
@@ -28,17 +28,14 @@
Index: src/PHPT/Case.php
===================================================================
--- src/PHPT/Case.php (revision 691)
+++ src/PHPT/Case.php (working copy)
@@ -28,17 +28,14 @@
{
$reporter->onCaseStart($this);
try {
@@ -26,7 +26,7 @@ Index: src/PHPT/Case.php
}
$reporter->onCasePass($this);
} catch (PHPT_Case_VetoException $veto) {
@@ -46,7 +43,6 @@
@@ -46,7 +43,6 @@
} catch (PHPT_Case_FailureException $failure) {
$reporter->onCaseFail($this, $failure);
}
@@ -34,11 +34,11 @@ Index: src/PHPT/Case.php
$reporter->onCaseEnd($this);
}
Index: src/PHPT/Case/Validator/CgiRequired.php
===================================================================
--- src/PHPT/Case/Validator/CgiRequired.php (revision 691)
+++ src/PHPT/Case/Validator/CgiRequired.php (working copy)
@@ -17,7 +17,6 @@
Index: src/PHPT/Case/Validator/CgiRequired.php
===================================================================
--- src/PHPT/Case/Validator/CgiRequired.php (revision 691)
+++ src/PHPT/Case/Validator/CgiRequired.php (working copy)
@@ -17,7 +17,6 @@
public function is(PHPT_Case $case)
{
$return = $case->sections->filterByInterface('CgiExecutable')->valid();
@@ -46,11 +46,11 @@ Index: src/PHPT/Case/Validator/CgiRequired.php
return $return;
}
}
Index: src/PHPT/CodeRunner/CommandLine.php
===================================================================
--- src/PHPT/CodeRunner/CommandLine.php (revision 691)
+++ src/PHPT/CodeRunner/CommandLine.php (working copy)
@@ -13,7 +13,7 @@
Index: src/PHPT/CodeRunner/CommandLine.php
===================================================================
--- src/PHPT/CodeRunner/CommandLine.php (revision 691)
+++ src/PHPT/CodeRunner/CommandLine.php (working copy)
@@ -13,7 +13,7 @@
$this->_filename = $runner->filename;
$this->_ini = (string)$runner->ini;
$this->_args = (string)$runner->args;
@@ -59,45 +59,45 @@ Index: src/PHPT/CodeRunner/CommandLine.php
$this->_post_filename = (string)$runner->post_filename;
}
Index: src/PHPT/CodeRunner/Driver/WScriptShell.php
===================================================================
--- src/PHPT/CodeRunner/Driver/WScriptShell.php (revision 691)
+++ src/PHPT/CodeRunner/Driver/WScriptShell.php (working copy)
@@ -23,9 +23,9 @@
}
}
if ($found == false) {
- throw new PHPT_CodeRunner_InvalidExecutableException(
- 'unable to locate PHP executable: ' . $this->executable
- );
+ //throw new PHPT_CodeRunner_InvalidExecutableException(
+ // 'unable to locate PHP executable: ' . $this->executable
+ //);
}
}
@@ -69,7 +69,7 @@
$error = $this->_process->StdErr->ReadAll();
if (!empty($error)) {
- throw new PHPT_CodeRunner_ExecutionException($error);
+ throw new PHPT_CodeRunner_ExecutionException($error, $this->_commandFactory());
}
return $this->_process->StdOut->ReadAll();
@@ -93,6 +93,7 @@
{
$return = '';
foreach ($this->environment as $key => $value) {
+ $value = str_replace('&', '^&', $value);
$return .= "set {$key}={$value} & ";
}
return $return;
Index: src/PHPT/CodeRunner/Factory.php
===================================================================
--- src/PHPT/CodeRunner/Factory.php (revision 691)
+++ src/PHPT/CodeRunner/Factory.php (working copy)
@@ -33,7 +33,13 @@
Index: src/PHPT/CodeRunner/Driver/WScriptShell.php
===================================================================
--- src/PHPT/CodeRunner/Driver/WScriptShell.php (revision 691)
+++ src/PHPT/CodeRunner/Driver/WScriptShell.php (working copy)
@@ -23,9 +23,9 @@
}
}
if ($found == false) {
- throw new PHPT_CodeRunner_InvalidExecutableException(
- 'unable to locate PHP executable: ' . $this->executable
- );
+ //throw new PHPT_CodeRunner_InvalidExecutableException(
+ // 'unable to locate PHP executable: ' . $this->executable
+ //);
}
}
@@ -69,7 +69,7 @@
$error = $this->_process->StdErr->ReadAll();
if (!empty($error)) {
- throw new PHPT_CodeRunner_ExecutionException($error);
+ throw new PHPT_CodeRunner_ExecutionException($error, $this->_commandFactory());
}
return $this->_process->StdOut->ReadAll();
@@ -93,6 +93,7 @@
{
$return = '';
foreach ($this->environment as $key => $value) {
+ $value = str_replace('&', '^&', $value);
$return .= "set {$key}={$value} & ";
}
return $return;
Index: src/PHPT/CodeRunner/Factory.php
===================================================================
--- src/PHPT/CodeRunner/Factory.php (revision 691)
+++ src/PHPT/CodeRunner/Factory.php (working copy)
@@ -33,7 +33,13 @@
'php-cgi';
}
@@ -112,11 +112,11 @@ Index: src/PHPT/CodeRunner/Factory.php
$runner->executable = $runner->executable . '.exe';
}
try {
Index: src/PHPT/Section/ModifiableAbstract.php
===================================================================
--- src/PHPT/Section/ModifiableAbstract.php (revision 691)
+++ src/PHPT/Section/ModifiableAbstract.php (working copy)
@@ -15,12 +15,10 @@
Index: src/PHPT/Section/ModifiableAbstract.php
===================================================================
--- src/PHPT/Section/ModifiableAbstract.php (revision 691)
+++ src/PHPT/Section/ModifiableAbstract.php (working copy)
@@ -15,12 +15,10 @@
public function run(PHPT_Case $case)
{
@@ -133,11 +133,11 @@ Index: src/PHPT/Section/ModifiableAbstract.php
}
}
Index: src/PHPT/Section/SKIPIF.php
===================================================================
--- src/PHPT/Section/SKIPIF.php (revision 691)
+++ src/PHPT/Section/SKIPIF.php (working copy)
@@ -3,10 +3,12 @@
Index: src/PHPT/Section/SKIPIF.php
===================================================================
--- src/PHPT/Section/SKIPIF.php (revision 691)
+++ src/PHPT/Section/SKIPIF.php (working copy)
@@ -3,10 +3,12 @@
class PHPT_Section_SKIPIF implements PHPT_Section_RunnableBefore
{
private $_data = null;
@@ -150,7 +150,7 @@ Index: src/PHPT/Section/SKIPIF.php
}
public function run(PHPT_Case $case)
@@ -16,9 +18,7 @@
@@ -16,9 +18,7 @@
// @todo refactor to PHPT_CodeRunner
file_put_contents($filename, $this->_data);
@@ -161,11 +161,11 @@ Index: src/PHPT/Section/SKIPIF.php
unlink($filename);
if (preg_match('/^skip( - (.*))?/', $response, $matches)) {
Index: src/PHPT/SectionList.php
===================================================================
--- src/PHPT/SectionList.php (revision 691)
+++ src/PHPT/SectionList.php (working copy)
@@ -2,7 +2,6 @@
Index: src/PHPT/SectionList.php
===================================================================
--- src/PHPT/SectionList.php (revision 691)
+++ src/PHPT/SectionList.php (working copy)
@@ -2,7 +2,6 @@
class PHPT_SectionList implements Iterator
{
@@ -173,7 +173,7 @@ Index: src/PHPT/SectionList.php
private $_sections = array();
private $_section_map = array();
private $_key_map = array();
@@ -15,14 +14,12 @@
@@ -15,14 +14,12 @@
}
$name = strtoupper(str_replace('PHPT_Section_', '', get_class($section)));
$key = $section instanceof PHPT_Section_Runnable ? $section->getPriority() . '.' . $name : $name;
@@ -190,7 +190,7 @@ Index: src/PHPT/SectionList.php
}
public function current()
@@ -52,21 +49,23 @@
@@ -52,21 +49,23 @@
public function filterByInterface($interface = null)
{
@@ -220,7 +220,7 @@ Index: src/PHPT/SectionList.php
}
public function has($name)
@@ -74,11 +73,11 @@
@@ -74,11 +73,11 @@
if (!isset($this->_section_map[$name])) {
return false;
}
@@ -234,11 +234,11 @@ Index: src/PHPT/SectionList.php
+ return $this->_sections[$this->_section_map[$key]];
}
}
Index: tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt
===================================================================
--- tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt (revision 691)
+++ tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt (working copy)
@@ -17,9 +17,9 @@
Index: tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt
===================================================================
--- tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt (revision 691)
+++ tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt (working copy)
@@ -17,9 +17,9 @@
// sanity check
$obj = new FoobarIni();
@@ -250,11 +250,11 @@ Index: tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt
unset($obj);
Index: tests/Section/File/restores-case-sections.phpt
===================================================================
--- tests/Section/File/restores-case-sections.phpt (revision 691)
+++ tests/Section/File/restores-case-sections.phpt (working copy)
@@ -1,24 +0,0 @@
Index: tests/Section/File/restores-case-sections.phpt
===================================================================
--- tests/Section/File/restores-case-sections.phpt (revision 691)
+++ tests/Section/File/restores-case-sections.phpt (working copy)
@@ -1,24 +0,0 @@
---TEST--
-After PHPT_Section_FILE::run(), the sections property of the provide $case object
-is restored to its unfiltered state
@@ -279,11 +279,11 @@ Index: tests/Section/File/restores-case-sections.phpt
-===DONE===
---EXPECT--
-===DONE===
Index: tests/SectionList/filter-by-interface.phpt
===================================================================
--- tests/SectionList/filter-by-interface.phpt (revision 691)
+++ tests/SectionList/filter-by-interface.phpt (working copy)
@@ -17,10 +17,10 @@
Index: tests/SectionList/filter-by-interface.phpt
===================================================================
--- tests/SectionList/filter-by-interface.phpt (revision 691)
+++ tests/SectionList/filter-by-interface.phpt (working copy)
@@ -17,10 +17,10 @@
$data = array_merge($runnable, $non_runnable);
$list = new PHPT_SectionList($data);
@@ -298,11 +298,11 @@ Index: tests/SectionList/filter-by-interface.phpt
?>
===DONE===
Index: tests/SectionList/filter-resets-with-null.phpt
===================================================================
--- tests/SectionList/filter-resets-with-null.phpt (revision 691)
+++ tests/SectionList/filter-resets-with-null.phpt (working copy)
@@ -1,36 +0,0 @@
Index: tests/SectionList/filter-resets-with-null.phpt
===================================================================
--- tests/SectionList/filter-resets-with-null.phpt (revision 691)
+++ tests/SectionList/filter-resets-with-null.phpt (working copy)
@@ -1,36 +0,0 @@
---TEST--
-If you call filterByInterface() with null or no-value, the full dataset is restored
---FILE--
@@ -339,11 +339,11 @@ Index: tests/SectionList/filter-resets-with-null.phpt
-===DONE===
---EXPECT--
-===DONE===
Index: tests/Util/Code/runAsFile-executes-in-file.phpt
===================================================================
--- tests/Util/Code/runAsFile-executes-in-file.phpt (revision 691)
+++ tests/Util/Code/runAsFile-executes-in-file.phpt (working copy)
@@ -10,7 +10,7 @@
Index: tests/Util/Code/runAsFile-executes-in-file.phpt
===================================================================
--- tests/Util/Code/runAsFile-executes-in-file.phpt (revision 691)
+++ tests/Util/Code/runAsFile-executes-in-file.phpt (working copy)
@@ -10,7 +10,7 @@
$util = new PHPT_Util_Code($code);
@@ -352,11 +352,11 @@ Index: tests/Util/Code/runAsFile-executes-in-file.phpt
$result = $util->runAsFile($file);
assert('$result == $file');
Index: tests/Util/Code/runAsFile-returns-output-if-no-return.phpt
===================================================================
--- tests/Util/Code/runAsFile-returns-output-if-no-return.phpt (revision 691)
+++ tests/Util/Code/runAsFile-returns-output-if-no-return.phpt (working copy)
@@ -9,7 +9,7 @@
Index: tests/Util/Code/runAsFile-returns-output-if-no-return.phpt
===================================================================
--- tests/Util/Code/runAsFile-returns-output-if-no-return.phpt (revision 691)
+++ tests/Util/Code/runAsFile-returns-output-if-no-return.phpt (working copy)
@@ -9,7 +9,7 @@
$util = new PHPT_Util_Code($code);