Merge pull request #4884 from nextcloud/enh/noid/use-str_contains

domain-validator: use `str_contains` instead of `strpos`
This commit is contained in:
Simon L 2024-06-24 14:53:04 +02:00 committed by GitHub
commit 5656f50bd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View file

@ -2,11 +2,11 @@
$domain = $_GET['domain'] ?? ''; $domain = $_GET['domain'] ?? '';
if (strpos($domain, '.') === false) { if (!str_contains($domain, '.')) {
http_response_code(400); http_response_code(400);
} elseif (strpos($domain, '/') !== false) { } elseif (str_contains($domain, '/')) {
http_response_code(400); http_response_code(400);
} elseif (strpos($domain, ':') !== false) { } elseif (str_contains($domain, ':')) {
http_response_code(400); http_response_code(400);
} elseif (filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false) { } elseif (filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false) {
http_response_code(400); http_response_code(400);

View file

@ -271,17 +271,17 @@ class ConfigurationManager
*/ */
public function SetDomain(string $domain) : void { public function SetDomain(string $domain) : void {
// Validate that at least one dot is contained // Validate that at least one dot is contained
if (strpos($domain, '.') === false) { if (!str_contains($domain, '.')) {
throw new InvalidSettingConfigurationException("Domain must contain at least one dot!"); throw new InvalidSettingConfigurationException("Domain must contain at least one dot!");
} }
// Validate that no slashes are contained // Validate that no slashes are contained
if (strpos($domain, '/') !== false) { if (str_contains($domain, '/')) {
throw new InvalidSettingConfigurationException("Domain must not contain slashes!"); throw new InvalidSettingConfigurationException("Domain must not contain slashes!");
} }
// Validate that no colons are contained // Validate that no colons are contained
if (strpos($domain, ':') !== false) { if (str_contains($domain, ':')) {
throw new InvalidSettingConfigurationException("Domain must not contain colons!"); throw new InvalidSettingConfigurationException("Domain must not contain colons!");
} }