WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 6 months ago

Last modified 6 months ago

#52417 closed enhancement (fixed)

Make filename checks less strict in `wp_image_src_get_dimensions`

Reported by: joemcgill Owned by: joemcgill
Milestone: 5.7 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

As a follow up to #51865, @ianmjones noted that wp_image_src_get_dimensions checks for the entire upload path when attempting to get the dimensions of full size images. For many reasons, this check can fail if the path has been changed. To make this less strict, we should be able to check to make sure the basename matches rather than the whole uploads path.

See the original comment.

Change History (11)

This ticket was mentioned in PR #972 on WordPress/wordpress-develop by joemcgill.


6 months ago

  • Keywords has-patch added

This modifies the check for full size files so that only the basename is compared with the image src to avoid misses whenever the src path has been modified.

Fixes: https://core.trac.wordpress.org/ticket/52417
Props ianmjones

#2 @joemcgill
6 months ago

  • Keywords commit added

#3 @antpb
6 months ago

Took a look at the patch and it makes sense and looks good to me, @joemcgill ! Tests are passing all around too.

#4 @prbot
6 months ago

mukeshpanchal27 commented on PR #972:

Hello,

As per the PHP Coding Standards document - https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions can we use Yoda Conditions here?

if ( strpos( $image_src, wp_basename( $image_meta['file'] ) ) !== false ) {

Replace to

if ( false !=== strpos( $image_src, wp_basename( $image_meta['file'] ) ) ) {

#5 @mukesh27
6 months ago

  • Keywords needs-refresh added

needs-refresh for the patch.

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

#6 @SergeyBiryukov
6 months ago

  • Component changed from General to Media

#7 @prbot
6 months ago

hellofromtonya commented on PR #972:

As per the PHP Coding Standards document - https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions can we use Yoda Conditions here?

Yoda Conditions doesn't apply in this case. Why? There's no variable on either side of the conditional expression. Instead, the expression compares a boolean literal false to a final result of the functions.

IMO the code is well-formed and understandable.

#8 @joemcgill
6 months ago

  • Keywords needs-refresh removed

Refreshed the patch to deal with merge conflicts after [50136].

#9 @hellofromTonya
6 months ago

Patch looks good @joemcgill. +1 for commit.

#10 @joemcgill
6 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 50144:

Media: Make filename checks less strict in 'wp_image_src_get_dimensions'.

This modifies the check for full size files so that only the basename is compared with the image src to avoid misses whenever the src path has been modified.

Props ianmjones.
Fixes: #52417.

Note: See TracTickets for help on using tickets.