Account for the fact that weird people put capital letters in URLs.

This commit is contained in:
flash 2023-05-21 18:11:01 +00:00
parent 70a4ce4cf5
commit 2be425eab3
4 changed files with 9 additions and 6 deletions

View file

@ -15,10 +15,11 @@ final class EEPROMLookup implements \Uiharu\ILookup {
) {}
public function match(Url $url): bool {
$urlHost = strtolower($url->getHost());
return $url->getScheme() === $this->protocol || (
$url->isWeb() && (
in_array($url->getHost(), $this->shortDomains) || (
$url->getHost() === $this->apiDomain && str_starts_with($url->getPath(), '/uploads')
in_array($urlHost, $this->shortDomains) || (
$urlHost === $this->apiDomain && str_starts_with($url->getPath(), '/uploads')
)
)
);

View file

@ -28,10 +28,12 @@ final class NicoNicoLookup implements \Uiharu\ILookup {
if(!$url->isWeb())
return false;
if(self::isShortDomain($url->getHost()))
$urlHost = strtolower($url->getHost());
if(self::isShortDomain($urlHost))
return true;
if(self::isLongDomain($url->getHost()) && str_starts_with($url->getPath(), '/watch/sm'))
if(self::isLongDomain($urlHost) && str_starts_with($url->getPath(), '/watch/sm'))
return true;
return false;

View file

@ -14,7 +14,7 @@ final class TwitterLookup implements \Uiharu\ILookup {
];
public function match(Url $url): bool {
if(!$url->isWeb() || !in_array($url->getHost(), self::TWITTER_DOMAINS))
if(!$url->isWeb() || !in_array(strtolower($url->getHost()), self::TWITTER_DOMAINS))
return false;
return preg_match('#^/@?(?:[A-Za-z0-9_]{1,20})/status(?:es)?/([0-9]+)/?$#', $url->getPath())

View file

@ -38,7 +38,7 @@ final class YouTubeLookup implements \Uiharu\ILookup {
if(!$url->isWeb())
return false;
$urlHost = $url->getHost();
$urlHost = strtolower($url->getHost());
if(self::isShortDomain($urlHost))
return true;