Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace '==' with '===' #4292

Closed
wants to merge 2 commits into from
Closed

Conversation

akramulhasan
Copy link

The WordPress PHP coding standards recommend using the strict equality operator '===' instead of '==' when checking conditions. This is because '==' performs type coercion, which can lead to unexpected results or security issues in some cases.
However, the WordPress core file wp-admin/update-core.php, on line 184, uses '=='. To ensure consistency with the WordPress coding standards and improve the security and stability of the code, I propose replacing '==' with '===' on this line.
This change will ensure that the comparison is performed using strict type checking, preventing any unexpected type coercion or security issues that may arise due to loose comparisons.
With this change, I will create a pull request to the WordPress core repository.

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


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

The WordPress core file wp-admin/update-core.php, on line 184, uses '=='. To ensure consistency with the WordPress coding standards and improve the security and stability of the code, I have replaced '==' with '===' on this line.
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @akramulhasan, Can you apply similar changes in line no 45?

The WordPress core file wp-admin/update-core.php, on line 45, uses '=='. To ensure consistency with the WordPress coding standards and improve the security and stability of the code, I have replaced '==' with '===' on this line.
@akramulhasan
Copy link
Author

Thank you so much @mukeshpanchal27 for your feedback
Yeah, I have made the change on line 45 and committed again.
Though I am very new to this system, not sure is this commit only enough or not. If need any further action, please let me know.
Thanks again for your help!

@azaozz
Copy link
Contributor

azaozz commented Apr 3, 2023

$wp_version as returned by get_bloginfo( 'version' ) seems to always be a string. However not so sure about $update->partial_version. Also seems there is a chance that get_bloginfo() may return something else as it just returns the global $wp_version which may have been changed by plugins.

Imho to be able to use strict comparison with full confidence both sides will have to be cast to (string).

@@ -42,7 +42,7 @@ function list_core_update( $update ) {

if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
$version_string = $update->current;
} elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
} elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version === $update->partial_version ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version === $update->partial_version ) {
} elseif ( 'en_US' === $update->locale && $update->packages->partial && (string) $wp_version === (string) $update->partial_version ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @azaozz

@@ -181,7 +181,7 @@ function list_core_update( $update ) {

if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version === $update->partial_version ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version === $update->partial_version ) ) {
} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && (string) $wp_version === (string) $update->partial_version ) ) {
@SergeyBiryukov
Copy link
Member

Thanks for the PR! Merged in r57529.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants