diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-18 11:46:37 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-22 15:25:23 +0200 |
commit | 2b7e5f841a016e8682d560643dce4797758a44c3 (patch) | |
tree | bc7216a8a82fe0986bae5ec9fecf33acbfe73275 /lib/private/share/helper.php | |
parent | d38a378b8cc8d13e6459ccb4cfbc8a8bbe1f8428 (diff) | |
download | nextcloud-server-2b7e5f841a016e8682d560643dce4797758a44c3.tar.gz nextcloud-server-2b7e5f841a016e8682d560643dce4797758a44c3.zip |
Merge spliteUserRemote with fixRemoteUrlInShareWith
Diffstat (limited to 'lib/private/share/helper.php')
-rw-r--r-- | lib/private/share/helper.php | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php index d88c4bcbfc2..5081a517db7 100644 --- a/lib/private/share/helper.php +++ b/lib/private/share/helper.php @@ -218,33 +218,25 @@ class Helper extends \OC\Share\Constants { } /** - * Extracts the necessary remote name from a given link + * Strips away a potential file names and trailing slashes: + * - http://localhost + * - http://localhost/ + * - http://localhost/index.php + * - http://localhost/index.php/s/{shareToken} * - * Strips away a potential file name, to allow - * - user - * - user@localhost - * - user@http://localhost - * - user@http://localhost/ - * - user@http://localhost/index.php - * - user@http://localhost/index.php/s/{shareToken} + * all return: http://localhost * * @param string $shareWith * @return string */ - public static function fixRemoteURLInShareWith($shareWith) { - if (strpos($shareWith, '@')) { - list($user, $remote) = explode('@', $shareWith, 2); - - $remote = str_replace('\\', '/', $remote); - if ($fileNamePosition = strpos($remote, '/index.php')) { - $remote = substr($remote, 0, $fileNamePosition); - } - $remote = rtrim($remote, '/'); - - $shareWith = $user . '@' . $remote; + protected static function fixRemoteURL($remote) { + $remote = str_replace('\\', '/', $remote); + if ($fileNamePosition = strpos($remote, '/index.php')) { + $remote = substr($remote, 0, $fileNamePosition); } + $remote = rtrim($remote, '/'); - return rtrim($shareWith, '/'); + return $remote; } /** @@ -255,10 +247,36 @@ class Helper extends \OC\Share\Constants { * @throws InvalidFederatedCloudIdException */ public static function splitUserRemote($id) { - $pos = strrpos($id, '@'); + if (strpos($id, '@') === false) { + throw new InvalidFederatedCloudIdException('invalid Federated Cloud ID'); + } + + // Find the first character that is not allowed in user names + $id = str_replace('\\', '/', $id); + $posSlash = strpos($id, '/'); + $posColon = strpos($id, ':'); + + if ($posSlash === false && $posColon === false) { + $invalidPos = strlen($id); + } else if ($posSlash === false) { + $invalidPos = $posColon; + } else if ($posColon === false) { + $invalidPos = $posSlash; + } else { + $invalidPos = min($posSlash, $posColon); + } + + // Find the last @ before $invalidPos + $pos = $lastAtPos = 0; + while ($lastAtPos !== false && $lastAtPos <= $invalidPos) { + $pos = $lastAtPos; + $lastAtPos = strpos($id, '@', $pos + 1); + } + if ($pos !== false) { $user = substr($id, 0, $pos); $remote = substr($id, $pos + 1); + $remote = self::fixRemoteURL($remote); if (!empty($user) && !empty($remote)) { return array($user, $remote); } |