1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-07 22:56:32 +02:00

[3.1.0] [BACKPORT] Fix bug with comments in styles, and some associated issues

- Restore printTokens()

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1570 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-02-20 00:15:44 +00:00
parent fbc595ebed
commit 6c9c8f2380
11 changed files with 98 additions and 42 deletions

View File

@@ -55,18 +55,6 @@ function isInScopes($array = array()) {
}
/**#@-*/
function printTokens($tokens, $index = null) {
$string = '<pre>';
$generator = new HTMLPurifier_Generator();
foreach ($tokens as $i => $token) {
if ($index === $i) $string .= '[<strong>';
$string .= "<sup>$i</sup>";
$string .= $generator->escape($generator->generateFromToken($token));
if ($index === $i) $string .= '</strong>]';
}
$string .= '</pre>';
echo $string;
}
/**
* The debugging singleton. Most interesting stuff happens here.

View File

@@ -168,6 +168,19 @@ text-align:right;
p p div {
text-align:left;
}"
);
}
function test_removeComments() {
$this->assertCleanCSS(
"<!--
div {
text-align:right;
}
-->",
"div {
text-align:right;
}"
);
}

View File

@@ -509,6 +509,29 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness
);
}
function test_tokenizeHTML_() {
$this->assertTokenization(
'<style type="text/css"><!--
div {}
--></style>',
array(
new HTMLPurifier_Token_Start('style', array('type' => 'text/css')),
new HTMLPurifier_Token_Text("\ndiv {}\n"),
new HTMLPurifier_Token_End('style'),
),
array(
// PH5P doesn't seem to like style tags
'PH5P' => false,
// DirectLex defers to RemoveForeignElements for textification
'DirectLex' => array(
new HTMLPurifier_Token_Start('style', array('type' => 'text/css')),
new HTMLPurifier_Token_Comment("\ndiv {}\n"),
new HTMLPurifier_Token_End('style'),
),
)
);
}
/*
function test_tokenizeHTML_() {

View File

@@ -159,4 +159,20 @@ function htmlpurifier_add_test($test, $test_file, $only_phpt = false) {
default:
trigger_error("$test_file is an invalid file for testing", E_USER_ERROR);
}
}
}
/**
* Debugging function that prints tokens in a user-friendly manner.
*/
function printTokens($tokens, $index = null) {
$string = '<pre>';
$generator = new HTMLPurifier_Generator();
foreach ($tokens as $i => $token) {
if ($index === $i) $string .= '[<strong>';
$string .= "<sup>$i</sup>";
$string .= $generator->escape($generator->generateFromToken($token));
if ($index === $i) $string .= '</strong>]';
}
$string .= '</pre>';
echo $string;
}