make TrustedDomainHelper case insensitive

Signed-off-by: Johannes Koenig <mail@jokoenig.de>
This commit is contained in:
Johannes Koenig 2019-10-06 20:43:55 +02:00
parent 1843ff60fd
commit 2df8d646c1
2 changed files with 6 additions and 1 deletions

View File

@ -90,7 +90,7 @@ class TrustedDomainHelper {
if (gettype($trusted) !== 'string') { if (gettype($trusted) !== 'string') {
break; break;
} }
$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/i';
if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
return true; return true;
} }

View File

@ -54,6 +54,8 @@ class TrustedDomainHelperTest extends \Test\TestCase {
'cen*ter', 'cen*ter',
'*.leadingwith.port:123', '*.leadingwith.port:123',
'trailingwith.port*:456', 'trailingwith.port*:456',
'UPPERCASE.DOMAIN',
'lowercase.domain',
]; ];
return [ return [
// empty defaults to false with 8.1 // empty defaults to false with 8.1
@ -106,6 +108,9 @@ class TrustedDomainHelperTest extends \Test\TestCase {
[$trustedHostTestList, '-bad', false], [$trustedHostTestList, '-bad', false],
[$trustedHostTestList, '-bad.leading.host', false], [$trustedHostTestList, '-bad.leading.host', false],
[$trustedHostTestList, 'bad..der.leading.host', false], [$trustedHostTestList, 'bad..der.leading.host', false],
// case sensitivity
[$trustedHostTestList, 'uppercase.domain', true],
[$trustedHostTestList, 'LOWERCASE.DOMAIN', true],
]; ];
} }
} }