Make WordPress Core

Opened 6 years ago

Last modified 12 months ago

#45493 reopened defect (bug)

Square brackets in caption shortcode produce improper formatting

Reported by: christian1012's profile Christian1012 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9.8
Component: Editor Keywords: has-patch needs-testing
Focuses: javascript 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 (4)

45493.diff (787 bytes) - added by Christian1012 6 years ago.
45493.1.diff (786 bytes) - added by Christian1012 4 years ago.
45493.2.diff (788 bytes) - added by Christian1012 4 years ago.
45493.3.diff (722 bytes) - added by sabernhardt 17 months ago.

Download all attachments as: .zip

Change History (14)

@Christian1012
6 years ago

#1 @Christian1012
6 years ago

  • Keywords has-patch added; needs-patch removed

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


4 years ago

#3 @kirasong
4 years 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
4 years 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 4 years ago by Christian1012 (previous) (diff)

#5 @Christian1012
4 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

#6 @Christian1012
4 years ago

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

#7 @sabernhardt
17 months ago

  • Focuses javascript added
  • Milestone changed from Future Release to 6.3

#8 @nataliat2004
16 months ago

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested: https://core.trac.wordpress.org/ticket/45493

Environment

  • OS: macOS 13.1
  • Web Server: Nginx
  • PHP: 8.0
  • WordPress: 6.3
  • Browser: Chrome 111.0.5563.146
  • Theme: Twenty Twenty-Three
  • Active Plugins:

Actual Results

  • The issue was not resolved with a patch. Also, the issue is not reproduced stably.
  • I tested it on Post and Page

Additional Notes

  • Steps to reproduce:
  • Paste the given text into the code editor
  • Switch to the visual editor
  • Back to the code editor.

Also, I checked on Draft and Publish and on the frontend.

Supplemental Artifacts

Add Inline:
Actual result:
https://monosnap.com/file/quHHlaobFzSHl6sv8zBfp4DSNXD01y
Expected result:
https://monosnap.com/file/fmupxPZFkZ3PrbQoaFI5sDmNXN7GL3

Last edited 13 months ago by sabernhardt (previous) (diff)

#9 @sabernhardt
13 months ago

  • Milestone changed from 6.3 to 6.4

#10 @sabernhardt
12 months ago

  • Milestone changed from 6.4 to Future Release
Note: See TracTickets for help on using tickets.