Make WordPress Core

Opened 10 years ago

Closed 10 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:

Description

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">
</div>

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 10 years ago.
34807.1.patch (1.6 KB) - added by azaozz 10 years ago.
34807.2.patch (4.1 KB) - added by azaozz 10 years ago.

Download all attachments as: .zip

Change History (13)

#1 @azaozz
10 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.

@azaozz
10 years ago

#2 @azaozz
10 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.


10 years ago

@azaozz
10 years ago

#4 @azaozz
10 years ago

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

#5 @wonderboymusic
10 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
10 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
10 years ago

  • Keywords commit added

@azaozz
10 years ago

#8 @azaozz
10 years ago

In 34807.2.patch: also add a test.

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


10 years ago

#10 @wonderboymusic
10 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.