From d6bf26da3c833e73573c944cea57ac436938322e Mon Sep 17 00:00:00 2001 From: rob1n Date: Fri, 1 Jun 2007 02:33:03 +0000 Subject: [PATCH] Fix nestable HTML, including
's. Props anonymousbugger (!) and Nazgul. fixes #1170 git-svn-id: https://develop.svn.wordpress.org/trunk@5623 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/formatting.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 12a9b538b5..e2204afbb6 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -439,6 +439,8 @@ function balanceTags($text, $force = false) { return $text; $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = ''; + $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags + $nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves # WP bug fix for comments - in case you REALLY meant to type '< !--' $text = str_replace('< !--', '< !--', $text); @@ -489,11 +491,11 @@ function balanceTags($text, $force = false) { if((substr($regex[2],-1) == '/') || ($tag == '')) { } // ElseIf it's a known single-entity tag but it doesn't close itself, do so - elseif ($tag == 'br' || $tag == 'img' || $tag == 'hr' || $tag == 'input') { + elseif ( in_array($tag, $single_tags) ) { $regex[2] .= '/'; } else { // Push the tag onto the stack // If the top of the stack is the same as the tag we want to push, close previous tag - if (($stacksize > 0) && ($tag != 'div') && ($tagstack[$stacksize - 1] == $tag)) { + if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) { $tagqueue = ''; $stacksize--; }