0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-03-23 14:27:02 +00:00

Implemented good behavior structure for fixNesting. Goes into infinite loop if bad stuff is passed.

Remove dud test and note which tests need to be added. Also, we're only running one test at a time to ease debugging.

git-svn-id: http://htmlpurifier.org/svnroot/html_purifier/trunk@57 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-07-19 00:21:21 +00:00
parent 2a2d8cbd76
commit 3e6bcb7a0f
2 changed files with 45 additions and 15 deletions

View File

@ -326,15 +326,48 @@ class PureHTMLDefinition
function fixNesting($tokens) { function fixNesting($tokens) {
if (empty($this->info)) $this->loadData(); if (empty($this->info)) $this->loadData();
/*$to_next_node = 0; // defines how much further to scroll to get // insert implicit "parent" node, will be removed at end
// to next node. array_unshift($tokens, new MF_StartTag('div'));
$tokens[] = new MF_EndTag('div');
for ($i = 0, $size = count($tokens) ; $i < $size; $i += $to_next_node) { for ($i = 0, $size = count($tokens) ; $i < $size; ) {
$child_tokens = array();
// scroll to the end of this node, and report number // scroll to the end of this node, and report number
for ($j = $i, $depth = 0; ; $j++) { for ($j = $i, $depth = 0; ; $j++) {
if ($tokens[$j]->type == 'start') {
$depth++;
if ($depth == 1) continue;
} elseif ($tokens[$j]->type == 'end') {
$depth--;
if ($depth == 0) break;
}
$child_tokens[] = $tokens[$j];
} }
}*/
// have DTD child def validate children
$element_def = $this->info[$tokens[$i]->name];
$result = $element_def->child_def->validateChildren($child_tokens);
// process result
if ($result === true) {
// leave the nodes as is, scroll to next node
$i++;
while ($i < $size and $tokens[$i]->type != 'start') {
$i++;
}
}
}
// remove implicit divs
array_shift($tokens);
array_pop($tokens);
return $tokens;
} }

View File

@ -413,17 +413,14 @@ class Test_PureHTMLDefinition extends UnitTestCase
new MF_EndTag('b'), new MF_EndTag('b'),
); );
// illegal <a> in <a> // need test of empty set that's required, resulting in removal of node
$inputs[3] = array(
new MF_StartTag('a'),
new MF_EndTag('a') // need test of cascading removal (if possible)
);
$expect[3] = array(
new MF_StartTag('a'),
new MF_EndTag('a') // ! cover all child element conditions
);
// execute only one test at a time:
$inputs = array( $inputs[0] );
foreach ($inputs as $i => $input) { foreach ($inputs as $i => $input) {
$result = $this->def->fixNesting($input); $result = $this->def->fixNesting($input);