PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Text » Text_Wiki_Mediawiki » Bug #8311

Wierd list format produces invalid tag nesting

Details

Submitted2006-07-27 23:24 UTC
Frombjs5075 at rit dot edu
Assignedritzmo
StatusClosed
PackageText_Wiki_Mediawiki
PHP Version5.1.4
OSDebian etch
Roadmaps(Not assigned)

Comments

[2006-07-27 23:24 UTC] bjs5075 at rit dot edu

Description:
------------
If the user skips levels while entering lists, the code does not keep track of this and eventually invalid XHTML is output. The parser needs to keep 'indenting' until it's at the right level.

The patch here queues-up as many levels as needed, and then inserts item-starts between them as necessary.

Here's a patch (hopefully won't get mangled too much):
--- design/software/Text_Wiki/Text/Wiki/Parse/Mediawiki/List.php (revision 501)
+++ design/software/Text_Wiki/Text/Wiki/Parse/Mediawiki/List.php (working copy)
@@ -139,23 +139,31 @@
$text = $val[3];

// add a level to the list?
- if ($level > count($stack)) {
-
+ $queue = array();
+ while ($level > count($stack)) {
// the current indent level is greater than the
// number of stack elements, so we must be starting
- // a new list. push the new list type onto the
- // stack...
- array_push($stack, $type);
-
- // ...and add a list-start token to the return.
- $return .= $this->wiki->addToken(
+ // a new list.
+ // add a list-start token to the temp insertion...
+ $queue[] = $this->wiki->addToken(
$this->rule,
array(
'type' => $type . '_list_start',
- 'level' => $level - 1
+ 'level' => count($stack)
)
);
+
+ // ...and push the new list type onto the stack.
+ array_push($stack, $type);
}
+ $return .= implode($this->wiki->addToken(
+ $this->rule,
+ array(
+ 'type' => $type . '_item_start',
+ 'level' => $level - 1
+ )),
+ $queue
+ );

// remove a level from the list?
while (count($stack) > $level) {

Test script:
---------------
* Level 1
*** Skipped a level
** Down to level2
* Almost done

Expected result:
----------------
Something like:

<ul>
<li>Level 1
<ul>
<li><!-- Level 2 -->
<ul>
<li>Skipped a level</li>
</ul>
<li>Down to level2</li>
</ul>
<li>Almost done</li>
</ul>

Actual result:
--------------
Semantically equivalent to:

<ul>
<li>Level 1
<ul>
<li>Skipped a level</li>
</ul>
<li>Down to level2</li>
</ul>
<li>Almost done</li>
</ul>

[2006-07-29 21:59 UTC] ritzmo at php dot net

Unfortunately your patch did not work correctly for me, so I implemented this feature (yeah, I think it's a feature :-)) on my own.
I left your arrays out and worked on a string-level which I think is a better way.

Comments welcome, new revision is in CVS.