Skip to content

Commit 5a0ea20

Browse files
Merge pull request #55250 from nextcloud/backport/55142/stable31
[stable31] fix: Allow hyphen in appid
2 parents 44bb50c + 315c0ea commit 5a0ea20

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/private/App/AppManager.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -175,9 +176,9 @@ public function getAllAppsInAppsFolders(): array {
175176
if (is_resource($dh)) {
176177
while (($file = readdir($dh)) !== false) {
177178
if (
178-
$file[0] != '.' &&
179-
is_dir($apps_dir['path'] . '/' . $file) &&
180-
is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')
179+
$file[0] != '.'
180+
&& is_dir($apps_dir['path'] . '/' . $file)
181+
&& is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')
181182
) {
182183
$apps[] = $file;
183184
}
@@ -525,8 +526,8 @@ public function loadApp(string $app): void {
525526

526527
if (!empty($info['collaboration']['plugins'])) {
527528
// deal with one or many plugin entries
528-
$plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
529-
[$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
529+
$plugins = isset($info['collaboration']['plugins']['plugin']['@value'])
530+
? [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
530531
$collaboratorSearch = null;
531532
$autoCompleteManager = null;
532533
foreach ($plugins as $plugin) {
@@ -945,6 +946,6 @@ public function isBackendRequired(string $backend): bool {
945946
*/
946947
public function cleanAppId(string $app): string {
947948
/* Only lowercase alphanumeric is allowed */
948-
return preg_replace('/(^[0-9_]|[^a-z0-9_]+|_$)/', '', $app);
949+
return preg_replace('/(^[0-9_-]+|[^a-z0-9_-]+|[_-]+$)/', '', $app);
949950
}
950951
}

tests/lib/App/AppManagerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,26 @@ public function testGetAppVersionUnknown() {
888888
);
889889
}
890890

891+
public static function dataCleanAppId(): array {
892+
return [
893+
['simple', 'simple'],
894+
['UPPERCASEa', 'a'],
895+
['MixEdCaSe', 'ixdae'],
896+
['007startwithdigit', 'startwithdigit'],
897+
['0-numb3rs-4ll0w3d-1n-m1ddle-0', 'numb3rs-4ll0w3d-1n-m1ddle-0'],
898+
['hyphen-and_underscore_allowed', 'hyphen-and_underscore_allowed'],
899+
['_but-not-at-the-end_', 'but-not-at-the-end'],
900+
['-but-not-at-the-end-', 'but-not-at-the-end'],
901+
['--_but-not-at-the-end___', 'but-not-at-the-end'],
902+
[' also remove all spaces', 'alsoremoveallspaces'],
903+
['a«"«»()@+-/*=%\{}…~|&œ—<>[]^±_−÷×≠‰A', 'a-_'],
904+
];
905+
}
906+
907+
/**
908+
* @dataProvider dataCleanAppId
909+
*/
910+
public function testCleanAppId(string $inputString, string $appid): void {
911+
$this->assertEquals($appid, $this->manager->cleanAppId($inputString));
912+
}
891913
}

0 commit comments

Comments
 (0)