Changeset 64300
- Timestamp:
- 10/11/2026 09:19:47 PM (4 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/canonical.php (modified) (1 diff)
-
tests/phpunit/tests/canonical.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/canonical.php
r64236 r64300 1006 1006 $query = "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "')"; 1007 1007 1008 $key = md5( $query ); 1008 // Remove the per-request placeholder escape so the cache key is stable across requests. 1009 $key = md5( $wpdb->remove_placeholder_escape( $query ) ); 1009 1010 $last_changed = wp_cache_get_last_changed( 'posts' ); 1010 1011 $cache_key = "redirect_guess_404_permalink:$key"; -
trunk/tests/phpunit/tests/canonical.php
r64043 r64300 441 441 442 442 /** 443 * Ensures the cache key does not contain the per-request `wpdb` placeholder escape. 444 * 445 * The placeholder escape string changes on every request, so a cache key derived from 446 * the escaped query could never be hit in a subsequent request. 447 * 448 * @ticket 66282 449 * @ticket 64250 450 * 451 * @covers ::redirect_guess_404_permalink 452 */ 453 public function test_redirect_guess_404_permalink_cache_key_excludes_placeholder_escape() { 454 $post = self::factory()->post->create( 455 array( 456 'post_title' => 'redirect-guess-404-permalink-cache-key', 457 ) 458 ); 459 460 $this->go_to( 'redirect-guess-404-permalink-cache-ke' ); 461 462 // The `query` filter receives the SQL after the placeholder escape has been removed. 463 $queries = array(); 464 $filter = static function ( $query ) use ( &$queries ) { 465 if ( str_contains( $query, 'post_name LIKE' ) ) { 466 $queries[] = $query; 467 } 468 return $query; 469 }; 470 471 add_filter( 'query', $filter ); 472 $guess = redirect_guess_404_permalink(); 473 remove_filter( 'query', $filter ); 474 475 $this->assertSame( get_permalink( $post ), $guess, 'Did not guess the correct permalink.' ); 476 $this->assertCount( 1, $queries, 'Expected exactly one loose-match query to be run.' ); 477 478 $cache = wp_cache_get_salted( 479 'redirect_guess_404_permalink:' . md5( $queries[0] ), 480 'post-queries', 481 wp_cache_get_last_changed( 'posts' ) 482 ); 483 484 $this->assertSame( $post, $cache, 'The cache key should be generated from the query without the placeholder escape.' ); 485 } 486 487 /** 443 488 * @ticket 64250 444 489 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)