#20740 closed defect (bug) (worksforme)
strip_shortcodes Chokes On Empty Shortcodes
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 3.3.2 |
Component: | Shortcodes | Keywords: | |
Focuses: | Cc: |
Description
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;
Can not reproduce with either of these code samples:
Closing out.