mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-23 14:27:02 +00:00
Fix bug in HTML_Generator that resulted in extra spaces. PureHTMLDefinition now passes all tests.
git-svn-id: http://htmlpurifier.org/svnroot/html_purifier/trunk@34 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
2782d7499a
commit
69da034570
@ -6,7 +6,7 @@ class HTML_Generator
|
|||||||
function generateFromToken($token) {
|
function generateFromToken($token) {
|
||||||
if (is_a($token, 'MF_StartTag')) {
|
if (is_a($token, 'MF_StartTag')) {
|
||||||
$attr = $this->generateAttributes($token->attributes);
|
$attr = $this->generateAttributes($token->attributes);
|
||||||
return '<' . $token->name . ' ' . $attr . '>';
|
return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>';
|
||||||
|
|
||||||
} elseif (is_a($token, 'MF_EndTag')) {
|
} elseif (is_a($token, 'MF_EndTag')) {
|
||||||
return '</' . $token->name . '>';
|
return '</' . $token->name . '>';
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
class PureHTMLDefinition
|
class PureHTMLDefinition
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var $generator;
|
||||||
var $info = array();
|
var $info = array();
|
||||||
|
|
||||||
function PureHTMLDefinition() {
|
function PureHTMLDefinition() {
|
||||||
|
$this->generator = new HTML_Generator();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadData() {
|
function loadData() {
|
||||||
@ -136,7 +137,10 @@ class PureHTMLDefinition
|
|||||||
$result = array();
|
$result = array();
|
||||||
foreach($tokens as $token) {
|
foreach($tokens as $token) {
|
||||||
if (is_subclass_of($token, 'MF_Tag')) {
|
if (is_subclass_of($token, 'MF_Tag')) {
|
||||||
if (!isset($this->info[$token->name])) continue;
|
if (!isset($this->info[$token->name])) {
|
||||||
|
// invalid tag, generate HTML and insert in
|
||||||
|
$token = new MF_Text($this->generator->generateFromToken($token));
|
||||||
|
}
|
||||||
} elseif (is_a($token, 'MF_Comment')) {
|
} elseif (is_a($token, 'MF_Comment')) {
|
||||||
// strip comments
|
// strip comments
|
||||||
continue;
|
continue;
|
||||||
|
@ -27,6 +27,9 @@ class UnitTest_HTML_Generator extends UnitTestCase
|
|||||||
$inputs[3] = new MF_EmptyTag('br', array('style' => 'font-family:"Courier New";'));
|
$inputs[3] = new MF_EmptyTag('br', array('style' => 'font-family:"Courier New";'));
|
||||||
$expect[3] = '<br style="font-family:"Courier New";" />';
|
$expect[3] = '<br style="font-family:"Courier New";" />';
|
||||||
|
|
||||||
|
$inputs[4] = new MF_StartTag('asdf');
|
||||||
|
$expect[4] = '<asdf>';
|
||||||
|
|
||||||
foreach ($inputs as $i => $input) {
|
foreach ($inputs as $i => $input) {
|
||||||
$result = $this->gen->generateFromToken($input);
|
$result = $this->gen->generateFromToken($input);
|
||||||
$this->assertEqual($result, $expect[$i]);
|
$this->assertEqual($result, $expect[$i]);
|
||||||
|
@ -28,6 +28,29 @@ class UnitTest_PureHTMLDefinition extends UnitTestCase
|
|||||||
);
|
);
|
||||||
$expect[1] = $inputs[1];
|
$expect[1] = $inputs[1];
|
||||||
|
|
||||||
|
$inputs[2] = array(
|
||||||
|
new MF_StartTag('asdf')
|
||||||
|
,new MF_EndTag('asdf')
|
||||||
|
,new MF_StartTag('d', array('href' => 'bang!'))
|
||||||
|
,new MF_EndTag('d')
|
||||||
|
,new MF_StartTag('pooloka')
|
||||||
|
,new MF_StartTag('poolasdf')
|
||||||
|
,new MF_StartTag('ds', array('moogle' => '&'))
|
||||||
|
,new MF_EndTag('asdf')
|
||||||
|
,new MF_EndTag('asdf')
|
||||||
|
);
|
||||||
|
$expect[2] = array(
|
||||||
|
new MF_Text('<asdf>')
|
||||||
|
,new MF_Text('</asdf>')
|
||||||
|
,new MF_Text('<d href="bang!">')
|
||||||
|
,new MF_Text('</d>')
|
||||||
|
,new MF_Text('<pooloka>')
|
||||||
|
,new MF_Text('<poolasdf>')
|
||||||
|
,new MF_Text('<ds moogle="&">')
|
||||||
|
,new MF_Text('</asdf>')
|
||||||
|
,new MF_Text('</asdf>')
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($inputs as $i => $input) {
|
foreach ($inputs as $i => $input) {
|
||||||
$result = $this->def->removeForeignElements($input);
|
$result = $this->def->removeForeignElements($input);
|
||||||
$this->assertEqual($result, $expect[$i]);
|
$this->assertEqual($result, $expect[$i]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user