Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#15694 new defect (bug)

Caption Shortcode I/O Intolerant of "]" Char

Reported by: miqrogroove Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0.1
Component: Shortcodes Keywords: needs-patch needs-unit-tests 4.2-early
Focuses: Cc:


I've discovered that the "]" character can only be used in the media library itself. If I try to insert an image into a post using a caption like "[Test Caption]" then the post editor inserts three double quotes into the HTML attribute, invalidating the page markup. D:

[caption id="attachment_3" align="alignnone" width="300" caption="[Test Caption"]"]

In testing the output end of things, if I remove the extra double quote directly in MySQL, then the caption is not rendered at all on the post. This suggests there is more than one error in the code that is causing this problem. I was able to reproduce these symptoms on both versions I tested, 2.9.2 and 3.0.1.

Change History (8)

comment:1 @nacin4 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:2 @solarissmoke4 years ago

The problem is with the regex in get_shortcode_regex() which assumes that the first ] it comes across is the end of a shortcode tag, and it ignores the rest, thus breaking things.

For now I've added a note in the codex saying that the parser can't handle square brackets in attributes. Can't think of a way to fix this without making the regex a whole lot more complicated.

comment:4 @hidgw3 years ago

  • Cc hidgw added

comment:5 @azaozz3 years ago

The shortcodes work similarly to HTML with [ and ] being the equivalent of < and >. In that terms shortcodes cannot contain square brackets the same way HTML tags cannot contain "less than" and "greater than" chars. If they must be used, they need to be encoded/replaced with entities.

comment:6 @ircbot10 months ago

This ticket was mentioned in IRC in #wordpress-dev by miqrogroove. View the logs.

comment:7 @ircbot10 months ago

This ticket was mentioned in IRC in #wordpress-dev by miqrogroove. View the logs.

comment:8 @miqrogroove5 months ago

  • Keywords needs-patch needs-unit-tests 4.2-early added

We need to fix this soon and add appropriate escape/unescape functions to the API. Consider it at the top of my to do list.

Note: See TracTickets for help on using tickets.