Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#52417 closed enhancement (fixed)

Make filename checks less strict in `wp_image_src_get_dimensions`

Reported by: joemcgill's profile joemcgill Owned by: joemcgill's profile 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.


3 years ago
#1

  • 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
3 years ago

  • Keywords commit added

#3 @antpb
3 years ago

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

mukeshpanchal27 commented on PR #972:


3 years ago
#4

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
3 years ago

  • Keywords needs-refresh added

needs-refresh for the patch.

Last edited 3 years ago by mukesh27 (previous) (diff)

#6 @SergeyBiryukov
3 years ago

  • Component changed from General to Media

hellofromtonya commented on PR #972:


3 years ago
#7

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
3 years ago

  • Keywords needs-refresh removed

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

#9 @hellofromTonya
3 years ago

Patch looks good @joemcgill. +1 for commit.

#10 @joemcgill
3 years 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.