mirror of
https://github.com/nextcloud/server.git
synced 2026-02-12 07:14:44 -05:00
Merge pull request #46012 from nextcloud/backport/45999/stable29
[stable29] fix(caldav): encode calendar URIs with umlauts for activities
This commit is contained in:
commit
440968fe2c
2 changed files with 62 additions and 8 deletions
|
|
@ -97,14 +97,15 @@ class Event extends Base {
|
|||
// The calendar app needs to be manually loaded for the routes to be loaded
|
||||
OC_App::loadApp('calendar');
|
||||
$linkData = $eventData['link'];
|
||||
$calendarUri = $this->urlencodeLowerHex($linkData['calendar_uri']);
|
||||
if ($affectedUser === $linkData['owner']) {
|
||||
$objectId = base64_encode($this->url->getWebroot() . '/remote.php/dav/calendars/' . $linkData['owner'] . '/' . $linkData['calendar_uri'] . '/' . $linkData['object_uri']);
|
||||
$objectId = base64_encode($this->url->getWebroot() . '/remote.php/dav/calendars/' . $linkData['owner'] . '/' . $calendarUri . '/' . $linkData['object_uri']);
|
||||
} else {
|
||||
// Can't use the "real" owner and calendar names here because we create a custom
|
||||
// calendar for incoming shares with the name "<calendar>_shared_by_<sharer>".
|
||||
// Hack: Fix the link by generating it for the incoming shared calendar instead,
|
||||
// as seen from the affected user.
|
||||
$objectId = base64_encode($this->url->getWebroot() . '/remote.php/dav/calendars/' . $affectedUser . '/' . $linkData['calendar_uri'] . '_shared_by_' . $linkData['owner'] . '/' . $linkData['object_uri']);
|
||||
$objectId = base64_encode($this->url->getWebroot() . '/remote.php/dav/calendars/' . $affectedUser . '/' . $calendarUri . '_shared_by_' . $linkData['owner'] . '/' . $linkData['object_uri']);
|
||||
}
|
||||
$link = [
|
||||
'view' => 'dayGridMonth',
|
||||
|
|
@ -262,4 +263,16 @@ class Event extends Base {
|
|||
}
|
||||
return $parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return urlencoded string but with lower cased hex sequences.
|
||||
* The remaining casing will be untouched.
|
||||
*/
|
||||
private function urlencodeLowerHex(string $raw): string {
|
||||
return preg_replace_callback(
|
||||
'/%[0-9A-F]{2}/',
|
||||
static fn (array $matches) => strtolower($matches[0]),
|
||||
urlencode($raw),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,17 +146,58 @@ class EventTest extends TestCase {
|
|||
$this->assertEquals($result, $this->invokePrivate($this->provider, 'generateObjectParameter', [$objectParameter, $affectedUser]));
|
||||
}
|
||||
|
||||
public function testGenerateObjectParameterWithSharedCalendar(): void {
|
||||
$link = [
|
||||
'object_uri' => 'someuuid.ics',
|
||||
'calendar_uri' => 'personal',
|
||||
'owner' => 'sharer'
|
||||
public static function generateObjectParameterLinkEncodingDataProvider(): array {
|
||||
return [
|
||||
[ // Shared calendar
|
||||
[
|
||||
'object_uri' => 'someuuid.ics',
|
||||
'calendar_uri' => 'personal',
|
||||
'owner' => 'sharer'
|
||||
],
|
||||
base64_encode('/remote.php/dav/calendars/sharee/personal_shared_by_sharer/someuuid.ics'),
|
||||
],
|
||||
[ // Shared calendar with umlauts
|
||||
[
|
||||
'object_uri' => 'someuuid.ics',
|
||||
'calendar_uri' => 'umlaut_äüöß',
|
||||
'owner' => 'sharer'
|
||||
],
|
||||
base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'),
|
||||
],
|
||||
[ // Shared calendar with umlauts and mixed casing
|
||||
[
|
||||
'object_uri' => 'someuuid.ics',
|
||||
'calendar_uri' => 'Umlaut_äüöß',
|
||||
'owner' => 'sharer'
|
||||
],
|
||||
base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f_shared_by_sharer/someuuid.ics'),
|
||||
],
|
||||
[ // Owned calendar with umlauts
|
||||
[
|
||||
'object_uri' => 'someuuid.ics',
|
||||
'calendar_uri' => 'umlaut_äüöß',
|
||||
'owner' => 'sharee'
|
||||
],
|
||||
base64_encode('/remote.php/dav/calendars/sharee/umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'),
|
||||
],
|
||||
[ // Owned calendar with umlauts and mixed casing
|
||||
[
|
||||
'object_uri' => 'someuuid.ics',
|
||||
'calendar_uri' => 'Umlaut_äüöß',
|
||||
'owner' => 'sharee'
|
||||
],
|
||||
base64_encode('/remote.php/dav/calendars/sharee/Umlaut_%c3%a4%c3%bc%c3%b6%c3%9f/someuuid.ics'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider generateObjectParameterLinkEncodingDataProvider */
|
||||
public function testGenerateObjectParameterLinkEncoding(array $link, string $objectId): void {
|
||||
$generatedLink = [
|
||||
'view' => 'dayGridMonth',
|
||||
'timeRange' => 'now',
|
||||
'mode' => 'sidebar',
|
||||
'objectId' => base64_encode('/remote.php/dav/calendars/sharee/' . $link['calendar_uri'] . '_shared_by_sharer/' . $link['object_uri']),
|
||||
'objectId' => $objectId,
|
||||
'recurrenceId' => 'next'
|
||||
];
|
||||
$this->appManager->expects($this->once())
|
||||
|
|
|
|||
Loading…
Reference in a new issue