WordPress.org

Make WordPress Core

Opened 22 months ago

Last modified 6 months ago

#45493 reopened defect (bug)

Square brackets in caption shortcode produce improper formatting

Reported by: Christian1012 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9.8
Component: Editor Keywords: has-patch needs-testing
Focuses: Cc:

Description

If [square] brackets are placed inside of a

[caption]

shortcode, the resulting formatting is broken when the captioned image is surrounded by text content.

If you paste the following into the text editor, switch to visual, and then back to text, you'll notice the line break after the caption disappears.

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

[caption id="attachment_143591" align="aligncenter" width="700"]<img class="size-full wp-image-143591" src="https://placehold.it/700x800" alt="" width="700" height="800" /> This is a caption with some [square] braces that make it appear like another shortcode.[/caption]

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

I'm not sure why this is happening, it may be related to some code thinking that the square brace inside the caption indicates it may be another shortcode. Escaping the shortcode using double brackets didn't have any affect.

Attachments (3)

45493.diff (787 bytes) - added by Christian1012 22 months ago.
45493.1.diff (786 bytes) - added by Christian1012 6 months ago.
45493.2.diff (788 bytes) - added by Christian1012 6 months ago.

Download all attachments as: .zip

Change History (9)

#1 @Christian1012
22 months ago

  • Keywords has-patch added; needs-patch removed

This ticket was mentioned in Slack in #core by noisysocks. View the logs.


6 months ago

#3 @mikeschroder
6 months ago

  • Keywords reporter-feedback needs-testing added
  • Milestone changed from Awaiting Review to Future Release

Hi @Christian1012 ! Thanks so much for the ticket and the patch, and apologies for the long wait on a reply.

We talked about this in today's triage.

Multiple folks were able to confirm the issue, but I still saw the problem after applying the patch.

Would you mind taking a look to see if it's still fixing the problem for you?

Either way, I'm going to mark it Future Release, since the bug is reproducible.

Thanks again!

#4 @Christian1012
6 months ago

  • Keywords reporter-feedback removed
  • Resolution set to invalid
  • Status changed from new to closed

Sorry this was a while ago. The patch I attached adds support for escaping brackets inside shortcodes, using the escaping method introduced in #6518.

[caption] Double brackets are [[escaped]] with entities. [/caption]

I tested the original patch, still seems to work for me, as long as you double escape. Adding an updated patch with proper formatting.

Last edited 6 months ago by Christian1012 (previous) (diff)

#5 @Christian1012
6 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

#6 @Christian1012
6 months ago

On thinking more about this, it might just make sense to escape brackets inside the captions.

Note: See TracTickets for help on using tickets.