Skip to content

Commit 4c6616f

Browse files
committed
Validate the website field input to be a valid URL
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent a219fa5 commit 4c6616f

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

apps/settings/lib/Controller/UsersController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ protected function saveUserSettings(IUser $user, array $data): array {
496496
if ($e->getMessage() === IAccountManager::PROPERTY_PHONE) {
497497
throw new \InvalidArgumentException($this->l10n->t('Unable to set invalid phone number'));
498498
}
499+
if ($e->getMessage() === IAccountManager::PROPERTY_WEBSITE) {
500+
throw new \InvalidArgumentException($this->l10n->t('Unable to set invalid website'));
501+
}
499502
throw new \InvalidArgumentException($this->l10n->t('Some account data was invalid'));
500503
}
501504
}

lib/private/Accounts/AccountManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ public function updateUser(IUser $user, array $data, bool $throwOnData = false):
144144
}
145145
}
146146

147+
if (isset($data[self::PROPERTY_WEBSITE])
148+
&& $data[self::PROPERTY_WEBSITE]['value'] !== ''
149+
&& filter_var($data[self::PROPERTY_WEBSITE]['value'], FILTER_VALIDATE_URL) === false) {
150+
if ($throwOnData) {
151+
throw new \InvalidArgumentException(self::PROPERTY_WEBSITE);
152+
}
153+
$data[self::PROPERTY_WEBSITE]['value'] = '';
154+
}
155+
147156
if (empty($userData)) {
148157
$this->insertNewUser($user, $data);
149158
} elseif ($userData !== $data) {

0 commit comments

Comments
 (0)