Changeset 58822
- Timestamp:
- 07/29/2024 01:57:11 AM (17 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/link-template.php (modified) (4 diffs)
-
tests/phpunit/tests/avatar.php (modified) (3 diffs)
-
tests/phpunit/tests/rest-api/rest-schema-setup.php (modified) (1 diff)
-
tests/qunit/fixtures/wp-api-generated.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/link-template.php
r58807 r58822 4329 4329 * 4330 4330 * @since 4.2.0 4331 * @since 6.7.0 Gravatar URLs always use HTTPS. 4331 4332 * 4332 4333 * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, … … 4359 4360 * Default is the value of the 'avatar_rating' option. 4360 4361 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. 4362 * For Gravatars this setting is ignored and HTTPS is used to avoid 4363 * unnecessary redirects. The setting is retained for systems using 4364 * the {@see 'pre_get_avatar_data'} filter to customize avatars. 4361 4365 * Default null. 4362 4366 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args … … 4509 4513 if ( $email_hash ) { 4510 4514 $args['found_avatar'] = true; 4511 $gravatar_server = hexdec( $email_hash[0] ) % 3;4512 } else {4513 $gravatar_server = rand( 0, 2 );4514 4515 } 4515 4516 … … 4521 4522 ); 4522 4523 4523 if ( is_ssl() ) { 4524 $url = 'https://secure.gravatar.com/avatar/' . $email_hash; 4525 } else { 4526 $url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash ); 4527 } 4524 /* 4525 * Gravatars are always served over HTTPS. 4526 * 4527 * The Gravatar website redirects HTTP requests to HTTPS URLs so always 4528 * use the HTTPS scheme to avoid unnecessary redirects. 4529 */ 4530 $url = 'https://secure.gravatar.com/avatar/' . $email_hash; 4528 4531 4529 4532 $url = add_query_arg( 4530 4533 rawurlencode_deep( array_filter( $url_args ) ), 4531 set_url_scheme( $url, $args['scheme'] )4534 $url 4532 4535 ); 4533 4536 -
trunk/tests/phpunit/tests/avatar.php
r56547 r58822 12 12 public function test_get_avatar_url_gravatar_url() { 13 13 $url = get_avatar_url( 1 ); 14 $this->assertSame( preg_match( '|^http ?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $url ), 1 );14 $this->assertSame( preg_match( '|^https?://secure.gravatar.com/avatar/[0-9a-f]{32}\?|', $url ), 1 ); 15 15 } 16 16 … … 57 57 58 58 /** 59 * @ticket 21195 59 * Ensures the get_avatar_url always returns an HTTPS scheme for gravatars. 60 * 61 * @ticket 21195 62 * @ticket 37454 63 * 64 * @covers ::get_avatar_url 60 65 */ 61 66 public function test_get_avatar_url_scheme() { 62 67 $url = get_avatar_url( 1 ); 63 $this->assertSame( preg_match( '|^http ://|', $url ), 1);68 $this->assertSame( preg_match( '|^https://|', $url ), 1, 'Avatars should default to the HTTPS scheme' ); 64 69 65 70 $args = array( 'scheme' => 'https' ); 66 71 $url = get_avatar_url( 1, $args ); 67 $this->assertSame( preg_match( '|^https://|', $url ), 1 ); 72 $this->assertSame( preg_match( '|^https://|', $url ), 1, 'Requesting the HTTPS scheme should be respected' ); 73 74 $args = array( 'scheme' => 'http' ); 75 $url = get_avatar_url( 1, $args ); 76 $this->assertSame( preg_match( '|^https://|', $url ), 1, 'Requesting the HTTP scheme should return an HTTPS URL to avoid redirects' ); 68 77 69 78 $args = array( 'scheme' => 'lolcat' ); 70 79 $url = get_avatar_url( 1, $args ); 71 $this->assertSame( preg_match( '|^lolcat://|', $url ), 0 ); 80 $this->assertSame( preg_match( '|^lolcat://|', $url ), 0, 'Unrecognized schemes should be ignored' ); 81 $this->assertSame( preg_match( '|^https://|', $url ), 1, 'Unrecognized schemes should return an HTTPS URL' ); 72 82 } 73 83 … … 258 268 259 269 $this->assertTrue( is_avatar_comment_type( $comment_type ) ); 260 $this->assertMatchesRegularExpression( '|^http ?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] );270 $this->assertMatchesRegularExpression( '|^https?://secure.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] ); 261 271 } 262 272 -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r58340