Extend MD_STD_IN::sanitize_url to automatically set protocol / scheme
names in lowercase
This commit is contained in:
parent
66e704de47
commit
0fb368b96d
|
@ -233,8 +233,16 @@ final class MD_STD_IN {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for valid schemes
|
// Check for valid schemes
|
||||||
if (MD_STD::startsWithAny($output, ['https://', 'http://', 'ftp://']) === false) {
|
try {
|
||||||
throw new MDInvalidUrl("Invalid input URL");
|
if (MD_STD::startsWithAny($output, ['https://', 'http://', 'ftp://']) === false) {
|
||||||
|
throw new MDInvalidUrl("Invalid input URL" . PHP_EOL . $output . PHP_EOL . strtolower($output));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (MDInvalidUrl $e) {
|
||||||
|
if (MD_STD::startsWithAny(strtolower($output), ['https://', 'http://', 'ftp://']) === true) {
|
||||||
|
$output = strtolower(substr($output, 0, 8)) . substr($output, 8);
|
||||||
|
}
|
||||||
|
else throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\str_contains($output, '.') === false) {
|
if (\str_contains($output, '.') === false) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ final class MD_STD_TEST_PROVIDERS {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'Regular URL without path or query' => ['https://www.museum-digital.org', 'https://www.museum-digital.org'],
|
'Regular URL without path or query' => ['https://www.museum-digital.org', 'https://www.museum-digital.org'],
|
||||||
|
'URL with uppercase character in scheme' => ['Https://www.museum-digital.org', 'https://www.museum-digital.org'],
|
||||||
'URL with cyrillic characters, HTML-encoded ' => [
|
'URL with cyrillic characters, HTML-encoded ' => [
|
||||||
'https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4',
|
'https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4',
|
||||||
'https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4',
|
'https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4',
|
||||||
|
@ -98,6 +99,8 @@ final class MD_STD_TEST_PROVIDERS {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$output['Mail address is too long'] = [str_repeat("a", 10000) . '@example.com'];
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user