Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#58039 closed defect (bug) (invalid)

Fix non-strict checking issue on options-writing.php file

Reported by: faisalahammad's profile faisalahammad Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: coding-standards Cc:

Description

This PR fixes a non-strict checking issue on the WordPress file options-writing.php. Specifically, on line 209, the code uses the "==" operator instead of the "===" operator. This can cause unexpected behavior since the "==" operator can coerce values and compare them in unexpected ways.

The fix involves replacing the "==" operator with the "===" operator to perform a strict comparison between the value returned by the get_option() function and the integer 1. 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 ( 1 === get_option( 'blog_public' ) ) : ?>

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

Change History (6)

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


2 years ago
#1

  • Keywords has-patch added; needs-patch removed

This PR fixes a non-strict checking issue on the WordPress file options-writing.php. Specifically, on line 209, the code uses the "==" operator instead of the "===" operator. This can cause unexpected behavior since the "==" operator can coerce values and compare them in unexpected ways.

The fix involves replacing the "==" operator with the "===" operator to perform a strict comparison between the value returned by the get_option() function and the integer 1. 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 ( 1 === get_option( 'blog_public' ) ) : ?>

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

Trac ticket: 58039

#2 @audrasjb
2 years ago

  • Version trunk deleted

Hello and thanks for the ticket and patch @faisalahammad,

On a default and fresh WordPress installation, get_option( 'blog_public' ) returns a string, not an integer or a boolean, so actually, the proposed patch will probably break the condition.

Also, the above PR contains a lot of unrelated changes, and these changes contain some coding standards issues.

#3 @faisalahammad
2 years ago

Hi @audrasjb
Sorry about that, It was my first PR, so I wasn't sure how to handle this.

My VS Code extension auto formats lots of code, which made the issues. You may close the ticket.

Thank you

#4 @audrasjb
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Thanks for the feedback!
Closing this ticket for now :)

#5 @audrasjb
2 years ago

#58060 was marked as a duplicate.

#6 @SergeyBiryukov
2 years ago

  • Component changed from General to Administration
Note: See TracTickets for help on using tickets.