Make WordPress Core

Opened 21 months ago

Closed 3 months ago

#58041 closed defect (bug) (fixed)

Fix non-strict checking issue on /wp-admin/includes/upgrade.php file

Reported by: faisalahammad's profile faisalahammad Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.3
Component: General Keywords: has-patch
Focuses: coding-standards Cc:

Description

This PR fixes a non-strict checking issue on line 1419 of the /wp-admin/includes/upgrade.php file in WordPress core. The current code uses the "==" operator instead of the "===" operator, which can lead to unexpected behavior due to type coercion.

To fix this issue, we replace the "==" operator with the "===" operator to perform a strict comparison between the value of the $link->link_category variable and the integer 0. This ensures that the comparison is done in a type-safe way and that unexpected behavior is avoided.

The fixed code is as follows:

<?php
if ( 0 === $link->link_category ) ) {
    continue;
}

With this fix, the code in the upgrade.php file will be more reliable and less prone to unexpected behavior.

Change History (4)

This ticket was mentioned in PR #4277 on WordPress/wordpress-develop by @faisalahammad.


21 months ago
#1

  • Keywords has-patch added; needs-patch removed

This PR fixes a non-strict checking issue on line 1419 of the /wp-admin/includes/upgrade.php file in WordPress core. The current code uses the "==" operator instead of the "===" operator, which can lead to unexpected behavior due to type coercion.

To fix this issue, we replace the "==" operator with the "===" operator to perform a strict comparison between the value of the $link->link_category variable and the integer 0. This ensures that the comparison is done in a type-safe way and that unexpected behavior is avoided.

The fixed code is as follows:

{{{php
if ( 0 === $link->link_category ) ) {

continue;

}
}}}

With this fix, the code in the upgrade.php file will be more reliable and less prone to unexpected behavior.

Trac ticket: https://core.trac.wordpress.org/ticket/58041

#2 @SergeyBiryukov
3 months ago

#61989 was marked as a duplicate.

#3 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 6.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Please note that $link->link_category is a string here, so the strict comparison would not work as is, it would require casting to an integer: 0 === (int) $link->link_category.

#4 @SergeyBiryukov
3 months ago

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

In 58994:

Coding Standards: Use strict comparison in wp-admin/includes/upgrade.php.

Follow-up to [725], [1575], [1975], [2037], [2966], [3670], [4738], [11958], [12776], [14080], [14485], [32378].

Props faisalahammad, mujuonly, aristath, poena, afercia, SergeyBiryukov.
Fixes #58041, #61607.

Note: See TracTickets for help on using tickets.