Changeset 58822
- Timestamp:
- 07/29/2024 01:57:11 AM (2 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
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 r58822 730 730 'TagModel.meta.test_tag_meta' => '', 731 731 'UsersCollection.0.link' => 'http://example.org/?author=1', 732 'UsersCollection.0.avatar_urls.24' => 'http ://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=24&d=mm&r=g',733 'UsersCollection.0.avatar_urls.48' => 'http ://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=48&d=mm&r=g',734 'UsersCollection.0.avatar_urls.96' => 'http ://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=96&d=mm&r=g',732 'UsersCollection.0.avatar_urls.24' => 'https://secure.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=24&d=mm&r=g', 733 'UsersCollection.0.avatar_urls.48' => 'https://secure.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=48&d=mm&r=g', 734 'UsersCollection.0.avatar_urls.96' => 'https://secure.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=96&d=mm&r=g', 735 735 'UsersCollection.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/1', 736 736 'UsersCollection.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users', -
trunk/tests/qunit/fixtures/wp-api-generated.js
r58452 r58822 13749 13749 "slug": "admin", 13750 13750 "avatar_urls": { 13751 "24": "http ://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=24&d=mm&r=g",13752 "48": "http ://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=48&d=mm&r=g",13753 "96": "http ://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=96&d=mm&r=g"13751 "24": "https://secure.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=24&d=mm&r=g", 13752 "48": "https://secure.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=48&d=mm&r=g", 13753 "96": "https://secure.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=96&d=mm&r=g" 13754 13754 }, 13755 13755 "meta": { … … 13777 13777 "slug": "restapiclientfixtureuser", 13778 13778 "avatar_urls": { 13779 "24": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=24&d=mm&r=g",13780 "48": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g",13781 "96": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g"13779 "24": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=24&d=mm&r=g", 13780 "48": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g", 13781 "96": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g" 13782 13782 }, 13783 13783 "meta": { … … 13807 13807 "slug": "restapiclientfixtureuser", 13808 13808 "avatar_urls": { 13809 "24": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=24&d=mm&r=g",13810 "48": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g",13811 "96": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g"13809 "24": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=24&d=mm&r=g", 13810 "48": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g", 13811 "96": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g" 13812 13812 }, 13813 13813 "meta": { … … 13824 13824 "slug": "restapiclientfixtureuser", 13825 13825 "avatar_urls": { 13826 "24": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=24&d=mm&r=g",13827 "48": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g",13828 "96": "http ://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g"13826 "24": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=24&d=mm&r=g", 13827 "48": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g", 13828 "96": "https://secure.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g" 13829 13829 }, 13830 13830 "meta": { … … 13850 13850 "type": "comment", 13851 13851 "author_avatar_urls": { 13852 "24": "http ://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=24&d=mm&r=g",13853 "48": "http ://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g",13854 "96": "http ://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g"13852 "24": "https://secure.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=24&d=mm&r=g", 13853 "48": "https://secure.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g", 13854 "96": "https://secure.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g" 13855 13855 }, 13856 13856 "meta": { … … 13895 13895 "type": "comment", 13896 13896 "author_avatar_urls": { 13897 "24": "http ://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=24&d=mm&r=g",13898 "48": "http ://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g",13899 "96": "http ://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g"13897 "24": "https://secure.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=24&d=mm&r=g", 13898 "48": "https://secure.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g", 13899 "96": "https://secure.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g" 13900 13900 }, 13901 13901 "meta": {
Note: See TracChangeset
for help on using the changeset viewer.