Skip to content

Commit 262c5b0

Browse files
committed
Make webdav URL absolute according to spec
1 parent 0ffae09 commit 262c5b0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

apps/federatedfilesharing/lib/Controller/OcmController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public function processNotification($notificationType,
423423
*/
424424
protected function getProtocols() {
425425
return [
426-
'webdav' => '/public.php/webdav/'
426+
'webdav' => $this->urlGenerator->getAbsoluteURL('/public.php/webdav/')
427427
];
428428
}
429429

apps/files_sharing/lib/External/Storage.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,25 @@ protected function init() {
9696
$this->memcacheFactory,
9797
\OC::$server->getHTTPClientService()
9898
);
99+
$webDavEndpoint = $discoveryManager->getWebDavEndpoint($this->remote);
100+
// OCM endpoint is absolute, OC legacy is relative
101+
$isOcmWebDavEndpoint = \preg_match('#https?://#', $webDavEndpoint) === 1;
102+
if ($isOcmWebDavEndpoint) {
103+
// proto is anything before ://
104+
// host starts just after a proto and ends before the first slash
105+
// root starts from the first slash until the end and could be empty
106+
\preg_match_all(
107+
'#^(?<proto>https?)://(?<host>[^/]*)(?<root>.*)$#',
108+
$webDavEndpoint,
109+
$matches
110+
);
111+
$this->secure = $matches['proto'][0] === 'https';
112+
$this->host = $matches['host'][0];
113+
$this->root = isset($matches['root'][0]) ? $matches['root'][0] : '/';
114+
} else {
115+
$this->root = \rtrim($this->root, '/') . $webDavEndpoint;
116+
}
99117

100-
$this->root = \rtrim($this->root, '/') . $discoveryManager->getWebDavEndpoint($this->remote);
101118
if (!$this->root || $this->root[0] !== '/') {
102119
$this->root = '/' . $this->root;
103120
}

0 commit comments

Comments
 (0)