WordPress.org

Make WordPress Core

#23787 closed defect (bug) (fixed)

Gallery displayed even when the gallery shortcode is inside an HTML comment

Reported by: mark-k Owned by: SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.4
Component: Gallery Keywords: has-patch
Focuses: Cc:

Description

The gallery shortcode emits HTML comment which cause HTML to break when the shortcode is inside a comment as HTML doesn't support nested comments

Adding the following in the text editor

<!-- [gallery ids="423,424,202,155,148,150"] -->

generates the following HTML

<!-- 
		<style type='text/css'>
			#gallery-1 {
				margin: auto;
			}
			#gallery-1 .gallery-item {
				float: right;
				margin-top: 10px;
				text-align: center;
				width: 33%;
			}
			#gallery-1 img {
				border: 2px solid #cfcfcf;
			}
			#gallery-1 .gallery-caption {
				margin-left: 0;
			}
		</style>
		<!-- see gallery_shortcode() in wp-includes/media.php -->
...
-->

related #23786

Attachments (2)

gallery.patch (619 bytes) - added by mark-k 13 months ago.
23787.diff (818 bytes) - added by aaroncampbell 11 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 SergeyBiryukov13 months ago

  • Milestone changed from Awaiting Review to 3.6

I guess we could remove the HTML comment from gallery_shortcode() (as you suggested in #23786), it doesn't seem necessary.

comment:2 toscho13 months ago

  • Cc info@… added

comment:3 mark-k13 months ago

Lets see if I got patch creation right...

mark-k13 months ago

comment:4 mark-k13 months ago

  • Keywords has-patch added

comment:5 aaroncampbell11 months ago

It seems like putting a gallery shortcode inside an html comment in a little edge-case, gallery.patch looks like a simple fix and I don't think the comment offers enough of a benefit to justify keeping it.

aaroncampbell11 months ago

comment:6 aaroncampbell11 months ago

Nacin had a good idea, so 23787.diff moves the comment to a CSS comment instead of removing it.

comment:7 SergeyBiryukov11 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 24329:

Switch to a CSS comment in gallery_shortcode() to avoid breaking markup when the shortcode is used inside an HTML comment. props mark-k, aaroncampbell. fixes #23787.

Note: See TracTickets for help on using tickets.