Support » Fixing WordPress » bugs in balanceTags?

  • I’ve had a bunch of posts simply mangled by balanceTags. In cases where the tags aren’t balance, I’ve seen it end up EATING small chunks of text somewhere after the missing tag.
    I also found that it is processing comments, which I use for special functionality, and even if it’s not causing a problem, it shouldn’t be touching them at all! So, I added in a check for empty($tag) before adding it to the stack (and processing it further…), which seems like it should work — though I’m debugging that right now… 😉
    But the missing text is bugging me… It’s a DAMN good thing I do my long articles completely offline now. Is there a way to have balancetags return back something so that the admin screen can show “Posted, but tags were auto-balanced”, so I can hit BACK immediately and try to look for the problem? Plus maybe a hint as to the tag that is missing (which the tag stack should ‘know’, right?).
    -d

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have had this happen to me before too. We need to set up some test cases so the bug can be tracked down.

    Just posted a bug about this yesterday in the SF.net tracker, test case included:
    http://sourceforge.net/tracker/index.php?func=detail&aid=962432&group_id=51422&atid=463233
    This the test case:
    <b><i>tag soup!</b></i>test
    link

    And the result I get:
    <b><i>tag soup!</i></b>"http://www.google.com">test link

    I fixed my code to handle comments properly — just needed to still build up the $tag after detecting it initially blank (to get the contents out of [2] of the regexp). That cleans up the stack handling a lot, probably speeds up the code for people with a lot of inline comments.
    My case was something like
    text [more]
    [comment]
    [comment]
    text
    [ul]
    [li][strong]text[/strong]text[/li]
    … a bunch of times
    .. then one line missing the [/li]
    .. few more closed properly
    [/ul]
    text
    [comment]
    this text gets chopped off a bit at the start of the line.
    =======
    -d

    if you fixed it, could you share your code? 🙂 Perhaps the core developers are interested in those fixes… and I’m also interested in using this very cool function in one of my little apps.

    This is obviously just a portion of the balanceTags function, and I’m working off an earlier (non-1.2) codebase — though the code is likely near-identical…

    } else { // Begin Tag
    $tag = strtolower($regex[1]);
    $attributes = $regex[2];
    if (empty($tag)) {
    // echo "re0: $regex[0], re1: $regex[1], re2: $regex[2]\n<br>";
    } else {
    // echo "TAG: $tag\n<br>";
    // Tag Cleaning
    // Push if not img or br or hr
    if($tag != 'br' && $tag != 'img' && $tag != 'hr') {
    $stacksize = array_push ($tagstack, $tag);
    }
    // Attributes
    // $attributes = $regex[2];
    if($attributes) {
    // fix to avoid CSS defacements
    if ($is_comment) {
    $attributes = str_replace('style=', 'title=', $attributes);
    $attributes = str_replace('class=', 'title=', $attributes);
    $attributes = str_replace('id=', 'title=', $attributes);
    }
    $attributes = ' '.$attributes;
    }
    }
    // always build up new $tag, so we capture comments back...
    $tag = '<'.$tag.$attributes.'>';
    }

    -d

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.