Merge pull request #6151 from nextcloud/backport-6099-no-exception-on-sharee-error

[stable12] Catch exceptions on error of cloud id resolution
This commit is contained in:
Roeland Jago Douma 2017-08-23 15:59:33 +02:00 committed by GitHub
commit 9b3e70f554
2 changed files with 22 additions and 5 deletions

View File

@ -335,7 +335,12 @@ class ShareesAPIController extends OCSController {
}
$lowerSearch = strtolower($search);
foreach ($cloudIds as $cloudId) {
try {
list(, $serverUrl) = $this->splitUserRemote($cloudId);
} catch (\InvalidArgumentException $e) {
continue;
}
if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
if (strtolower($cloudId) === $lowerSearch) {
$result['exactIdMatch'] = true;
@ -386,14 +391,14 @@ class ShareesAPIController extends OCSController {
*
* @param string $address federated share address
* @return array [user, remoteURL]
* @throws \Exception
* @throws \InvalidArgumentException
*/
public function splitUserRemote($address) {
try {
$cloudId = $this->cloudIdManager->resolveCloudId($address);
return [$cloudId->getUser(), $cloudId->getRemote()];
} catch (\InvalidArgumentException $e) {
throw new \Exception('Invalid Federated Cloud ID', 0, $e);
throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
}
}
@ -610,7 +615,12 @@ class ShareesAPIController extends OCSController {
if (isset($contact['isLocalSystemBook'])) {
if ($exactEmailMatch) {
try {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
} catch (\InvalidArgumentException $e) {
continue;
}
if (!$this->hasUserInResult($cloud->getUser())) {
$this->result['exact']['users'][] = [
'label' => $contact['FN'] . " ($emailAddress)",
@ -622,8 +632,14 @@ class ShareesAPIController extends OCSController {
}
return ['results' => [], 'exact' => [], 'exactIdMatch' => true];
}
if ($this->shareeEnumeration) {
try {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
} catch (\InvalidArgumentException $e) {
continue;
}
if (!$this->hasUserInResult($cloud->getUser())) {
$this->result['users'][] = [
'label' => $contact['FN'] . " ($emailAddress)",

View File

@ -29,6 +29,7 @@ interface ICloudIdManager {
/**
* @param string $cloudId
* @return ICloudId
* @throws \InvalidArgumentException
*
* @since 12.0.0
*/