From 0c5a04d541681037cd5937fa2649022a78b75023 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 22 Apr 2023 15:19:22 +0000 Subject: [PATCH] Coding Standards: Use strict comparison where `strtolower()` is involved. Follow-up to [649], [7736], [18821], [19444], [20886], [20893], [23303], [55642], [55652], [55653], [55654]. Props aristath, poena, afercia, SergeyBiryukov. See #57839. Built from https://develop.svn.wordpress.org/trunk@55677 git-svn-id: http://core.svn.wordpress.org/trunk@55189 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/upgrade.php | 11 +++++++---- wp-includes/formatting.php | 21 +++++++++++++++++---- wp-includes/kses.php | 4 ++-- wp-includes/post.php | 5 ++++- wp-includes/theme.php | 4 ++-- wp-includes/version.php | 2 +- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 46f6286cad..8aa16ac7a3 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -1739,6 +1739,7 @@ function upgrade_330() { $_sidebars_widgets[ $index ][ $i ] = $id; continue; } + $id = sanitize_title( $name ); if ( isset( $wp_registered_widgets[ $id ] ) ) { $_sidebars_widgets[ $index ][ $i ] = $id; @@ -1748,13 +1749,15 @@ function upgrade_330() { $found = false; foreach ( $wp_registered_widgets as $widget_id => $widget ) { - if ( strtolower( $widget['name'] ) == strtolower( $name ) ) { + if ( strtolower( $widget['name'] ) === strtolower( $name ) ) { $_sidebars_widgets[ $index ][ $i ] = $widget['id']; - $found = true; + + $found = true; break; - } elseif ( sanitize_title( $widget['name'] ) == sanitize_title( $name ) ) { + } elseif ( sanitize_title( $widget['name'] ) === sanitize_title( $name ) ) { $_sidebars_widgets[ $index ][ $i ] = $widget['id']; - $found = true; + + $found = true; break; } } diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index ccf728236a..8240adcc82 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -3029,13 +3029,26 @@ function make_clickable( $text ) { $nested_code_pre = 0; // Keep track of how many levels link is nested inside
 or .
 	foreach ( $textarr as $piece ) {
 
-		if ( preg_match( '|^]|i', $piece ) || preg_match( '|^]|i', $piece ) || preg_match( '|^]|i', $piece ) || preg_match( '|^]|i', $piece ) ) {
+		if ( preg_match( '|^]|i', $piece )
+			|| preg_match( '|^]|i', $piece )
+			|| preg_match( '|^]|i', $piece )
+			|| preg_match( '|^]|i', $piece )
+		) {
 			$nested_code_pre++;
-		} elseif ( $nested_code_pre && ( '' === strtolower( $piece ) || '
' === strtolower( $piece ) || '' === strtolower( $piece ) || '' === strtolower( $piece ) ) ) { + } elseif ( $nested_code_pre + && ( '' === strtolower( $piece ) + || '' === strtolower( $piece ) + || '' === strtolower( $piece ) + || '' === strtolower( $piece ) + ) + ) { $nested_code_pre--; } - if ( $nested_code_pre || empty( $piece ) || ( '<' === $piece[0] && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) { + if ( $nested_code_pre + || empty( $piece ) + || ( '<' === $piece[0] && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) + ) { $r .= $piece; continue; } @@ -4463,7 +4476,7 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) { $protocols = wp_allowed_protocols(); } $good_protocol_url = wp_kses_bad_protocol( $url, $protocols ); - if ( strtolower( $good_protocol_url ) != strtolower( $url ) ) { + if ( strtolower( $good_protocol_url ) !== strtolower( $url ) ) { return ''; } } diff --git a/wp-includes/kses.php b/wp-includes/kses.php index f85f0b1366..eef6632487 100644 --- a/wp-includes/kses.php +++ b/wp-includes/kses.php @@ -1640,7 +1640,7 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { * If the given value is an "n" or an "N", the attribute must have a value. */ - if ( strtolower( $checkvalue ) != $vless ) { + if ( strtolower( $checkvalue ) !== $vless ) { $ok = false; } break; @@ -1846,7 +1846,7 @@ function wp_kses_bad_protocol_once2( $scheme, $allowed_protocols ) { $allowed = false; foreach ( (array) $allowed_protocols as $one_protocol ) { - if ( strtolower( $one_protocol ) == $scheme ) { + if ( strtolower( $one_protocol ) === $scheme ) { $allowed = true; break; } diff --git a/wp-includes/post.php b/wp-includes/post.php index 3c1af397a3..84c513cb82 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4194,7 +4194,10 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) // On updates, we need to check to see if it's using the old, fixed sanitization context. $check_name = sanitize_title( $post_name, '', 'old-save' ); - if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_id ) == $check_name ) { + if ( $update + && strtolower( urlencode( $post_name ) ) === $check_name + && get_post_field( 'post_name', $post_id ) === $check_name + ) { $post_name = $check_name; } else { // New post, or slug has changed. $post_name = sanitize_title( $post_name ); diff --git a/wp-includes/theme.php b/wp-includes/theme.php index c1623f4058..8cda0f14af 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -3625,7 +3625,7 @@ function _wp_customize_changeset_filter_insert_post_data( $post_data, $supplied_ function _wp_customize_loader_settings() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); - $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); + $cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) ); $browser = array( 'mobile' => wp_is_mobile(), @@ -3690,7 +3690,7 @@ function wp_customize_url( $stylesheet = '' ) { function wp_customize_support_script() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); - $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); + $cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) ); $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : ' type="text/javascript"'; ?> > diff --git a/wp-includes/version.php b/wp-includes/version.php index e9c70511a4..07e92d8e31 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55676'; +$wp_version = '6.3-alpha-55677'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.