From ace661dc824bbece4f018eead48ef2e9c685057a Mon Sep 17 00:00:00 2001 From: Rajinsharwar Date: Tue, 14 Nov 2023 18:34:54 -0500 Subject: [PATCH] Reverting back to old patch --- src/wp-includes/canonical.php | 2 +- tests/phpunit/includes/testcase-canonical.php | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php index 5aadaea4b956e..f0d701bf333ac 100644 --- a/src/wp-includes/canonical.php +++ b/src/wp-includes/canonical.php @@ -978,7 +978,7 @@ function redirect_guess_404_permalink() { $publicly_viewable_statuses = array_filter( get_post_stati(), 'is_post_status_viewable' ); $publicly_viewable_post_types = array_filter( get_post_types(), 'is_post_type_viewable' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN (%s) AND post_type IN (%s)", implode( "', '", esc_sql( $publicly_viewable_statuses ) ), implode( "', '", esc_sql( $publicly_viewable_post_types ) ) ) ); + $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "') AND post_type IN ('" . implode( "', '", esc_sql( $publicly_viewable_post_types ) ) . "')" ); if ( ! $post_id ) { return false; diff --git a/tests/phpunit/includes/testcase-canonical.php b/tests/phpunit/includes/testcase-canonical.php index b074d90ac9946..26916fac6e96b 100644 --- a/tests/phpunit/includes/testcase-canonical.php +++ b/tests/phpunit/includes/testcase-canonical.php @@ -287,59 +287,52 @@ public static function delete_shared_fixtures() { */ public function assertCanonical( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, (array) $expected_doing_it_wrong ); - + $ticket_ref = ( $ticket > 0 ) ? 'Ticket #' . $ticket : ''; - + if ( is_string( $expected ) ) { $expected = array( 'url' => $expected ); } elseif ( is_array( $expected ) && ! isset( $expected['url'] ) && ! isset( $expected['qv'] ) ) { $expected = array( 'qv' => $expected ); } - + if ( ! isset( $expected['url'] ) && ! isset( $expected['qv'] ) ) { $this->fail( 'No valid expected output was provided' ); } - + $this->go_to( home_url( $test_url ) ); - + // Does the redirect match what's expected? $can_url = $this->get_canonical( $test_url ); $parsed_can_url = parse_url( $can_url ); - + // Just test the path and query if present. if ( isset( $expected['url'] ) ) { - // Check for post type privacy settings. - $post_type_obj = get_post_type_object( get_post_type() ); - if ( $post_type_obj && isset( $post_type_obj->publicly_queryable ) && ! $post_type_obj->publicly_queryable ) { - // If the post type is not publicly queryable, ignore the test. - return; - } - $this->assertSame( $expected['url'], $parsed_can_url['path'] . ( ! empty( $parsed_can_url['query'] ) ? '?' . $parsed_can_url['query'] : '' ), $ticket_ref ); } - + // If the test data doesn't include expected query vars, then we're done here. if ( ! isset( $expected['qv'] ) ) { return; } - + // "make" that the request and check the query is correct. $this->go_to( $can_url ); - + // Are all query vars accounted for, and correct? global $wp; - + $query_vars = array_diff( $wp->query_vars, $wp->extra_query_vars ); if ( ! empty( $parsed_can_url['query'] ) ) { parse_str( $parsed_can_url['query'], $_qv ); - + // $_qv should not contain any elements which are set in $query_vars already // (i.e. $_GET vars should not be present in the Rewrite). $this->assertSame( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref ); - + $query_vars = array_merge( $query_vars, $_qv ); } - + $this->assertEquals( $expected['qv'], $query_vars ); }