[wp-trac] [WordPress Trac] #20740: strip_shortcodes Chokes On Empty Shortcodes
WordPress Trac
wp-trac at lists.automattic.com
Wed May 23 22:58:57 UTC 2012
#20740: strip_shortcodes Chokes On Empty Shortcodes
--------------------------+-----------------------------
Reporter: MathSmath | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.3.2
Severity: minor | Keywords:
--------------------------+-----------------------------
It appears the regex for strip_shortcodes doesn't recognize empty
shortcodes. For example, a caption shortcode like this would only have the
opening shortcode tag stripped:
{{{
[caption id="attachment_3360" width="288" caption="Some
caption"][/caption]
}}}
The closing caption tag remains in the resulting string.
I realize this is a fringe case (why would you have an empty caption?),
but it popped up for me when working with a popular plugin that attempts
to generate an excerpt by doing the following:
{{{
$content = strip_tags($content);
$content = strip_shortcodes($content);
}}}
Seems harmless--but if a caption contains only an image tag, the
strip_tags removes it, and the strip_shortcodes chokes on the now-empty
shortcode. Or even worse, if you have a second caption shortcode in the
content, it strips EVERYTHING between the first opening caption tag and
the second closing caption tag.
And I have to imagine there are some custom shortcodes that may be
legitimately empty for some reason. I dunno.
To reproduce:
{{{
$content = '[caption][/caption]
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[caption][/caption]';
$content = strip_shortcodes($content);
echo $content;
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20740>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list