Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#34807 closed defect (bug) (fixed)

Image tags without ending slash are never made responsive.

Reported by: programmin's profile programmin Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: has-patch commit
Focuses: performance Cc:


If a page has this content:

<div>some content</div>
<div style="text-align: right;">more content</div>
<div style="text-align: center;">
<img class="alignnone size-full wp-image-2457" src="http://localhost/wordpress/wp-content/uploads/2015/11/IMG1275.jpg" alt="IMG1275" width="1536" height="2048">

the srcset is never added to the image - maybe a bug in wp_make_content_images_responsive() or get_media_embedded_in_content() as it returns empty array.

However, when I add an ending /> or </img> to the img tag it fixes it and I see srcset and responsive images.

Attachments (3)

34807.patch (814 bytes) - added by azaozz 8 years ago.
34807.1.patch (1.6 KB) - added by azaozz 8 years ago.
34807.2.patch (4.1 KB) - added by azaozz 8 years ago.

Download all attachments as: .zip

Change History (13)

#1 @azaozz
8 years ago

  • Component changed from General to Media
  • Milestone changed from Awaiting Review to 4.4

Confirmed. The bug is in get_media_embedded_in_content(). Why do we use that (buggy) function with longer regex for images anyway? If I remember right we had better and twice as fast regex specifically for images.

Using get_media_embedded_in_content() also has an unexpected/unintended side effect: img can be removed from the whitelist by using the media_embedded_in_content_allowed_types filter. That will of course prevent matching of any images.

8 years ago

#2 @azaozz
8 years ago

  • Keywords has-patch added

In 34807.patch: use specific (shorter and faster) regex to match all images in post_content. Fixes the above bug and returns early when no images.

This ticket was mentioned in Slack in #feature-respimg by azaozz. View the logs.

8 years ago

8 years ago

#4 @azaozz
8 years ago

In 34807.1.patch: also revert adding of img to get_media_embedded_in_content().

#5 @wonderboymusic
8 years ago

Yes, those functions should have been flushed down the toilet with most of the PF code from 3.6. They only existed to DRY when the internals would have otherwise been used 8-10 times. RIP

#6 @joemcgill
8 years ago

Works for me. Using get_media_embedded_in_content() was an idea introduced in #33641, which I wasn't super confident in at the time.

#7 @azaozz
8 years ago

  • Keywords commit added

8 years ago

#8 @azaozz
8 years ago

In 34807.2.patch: also add a test.

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

8 years ago

#10 @wonderboymusic
8 years ago

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

In 35753:

Media: don't use get_media_embedded_in_content() in wp_make_content_images_responsive().

Adds unit test.

Props azaozz.
Fixes #34807.

Note: See TracTickets for help on using tickets.