Skip to content

Commit 456c24e

Browse files
authored
fix: Fix a bug with URL check for avatars (#3002)
Fixes a bug introduced in #2947
1 parent 05af54f commit 456c24e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Comment.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ protected function avatar_default($default, $email, $size, $host)
588588
$default = $avatar_default;
589589
}
590590
}
591+
591592
if ('mystery' == $default) {
592593
$default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size;
593594
// ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]')
@@ -597,7 +598,7 @@ protected function avatar_default($default, $email, $size, $host)
597598
$default = '';
598599
} elseif ('gravatar_default' == $default) {
599600
$default = $host . '/avatar/?s=' . $size;
600-
} elseif (empty($email) && !\strstr($default, 'https://')) {
601+
} elseif (empty($email) && !\preg_match('/^https?:\/\//', $default)) {
601602
$default = $host . '/avatar/?d=' . $default . '&s=' . $size;
602603
}
603604
return $default;

tests/test-timber-comment-avatar.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testAvatarSimple()
124124
# pass custom url on different domain. can't check by crawling as
125125
# i get a 302 regardless of default url
126126
# so just check it comes back with it in the url
127-
$this->valid_avatar($comment, "https://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png");
127+
$this->valid_avatar($comment, 'https://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png');
128128

129129
# same domain.
130130
$this->valid_avatar($comment, $theme_url . "/images/default.png");
@@ -148,8 +148,9 @@ public function valid_avatar($comment, $default_url)
148148
# you get back the default in the avatar url?
149149
$this->assertEquals($params, "d=$default_url&s=32");
150150
}
151-
# you get back url?
152-
$this->assertTrue(substr($avatar, 0, 6) == "https:");
151+
152+
// Check if we get back an URL (either http:// or https:).
153+
$this->assertMatchesRegularExpression("/^https?:.*/", $avatar);
153154
}
154155

155156
public function crawl($url)

0 commit comments

Comments
 (0)