mirror of
https://github.com/nextcloud/server.git
synced 2026-05-14 01:21:32 -04:00
fix: Allow hyphen in appid
It’s rare but exists for some apps not in the appstore. Also added unit tests for cleanAppId and fixed small issues with it. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
99a9420081
commit
315c0ea59c
2 changed files with 29 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -175,9 +176,9 @@ class AppManager implements IAppManager {
|
|||
if (is_resource($dh)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if (
|
||||
$file[0] != '.' &&
|
||||
is_dir($apps_dir['path'] . '/' . $file) &&
|
||||
is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')
|
||||
$file[0] != '.'
|
||||
&& is_dir($apps_dir['path'] . '/' . $file)
|
||||
&& is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')
|
||||
) {
|
||||
$apps[] = $file;
|
||||
}
|
||||
|
|
@ -525,8 +526,8 @@ class AppManager implements IAppManager {
|
|||
|
||||
if (!empty($info['collaboration']['plugins'])) {
|
||||
// deal with one or many plugin entries
|
||||
$plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
|
||||
[$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
|
||||
$plugins = isset($info['collaboration']['plugins']['plugin']['@value'])
|
||||
? [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
|
||||
$collaboratorSearch = null;
|
||||
$autoCompleteManager = null;
|
||||
foreach ($plugins as $plugin) {
|
||||
|
|
@ -945,6 +946,6 @@ class AppManager implements IAppManager {
|
|||
*/
|
||||
public function cleanAppId(string $app): string {
|
||||
/* Only lowercase alphanumeric is allowed */
|
||||
return preg_replace('/(^[0-9_]|[^a-z0-9_]+|_$)/', '', $app);
|
||||
return preg_replace('/(^[0-9_-]+|[^a-z0-9_-]+|[_-]+$)/', '', $app);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -888,4 +888,26 @@ class AppManagerTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public static function dataCleanAppId(): array {
|
||||
return [
|
||||
['simple', 'simple'],
|
||||
['UPPERCASEa', 'a'],
|
||||
['MixEdCaSe', 'ixdae'],
|
||||
['007startwithdigit', 'startwithdigit'],
|
||||
['0-numb3rs-4ll0w3d-1n-m1ddle-0', 'numb3rs-4ll0w3d-1n-m1ddle-0'],
|
||||
['hyphen-and_underscore_allowed', 'hyphen-and_underscore_allowed'],
|
||||
['_but-not-at-the-end_', 'but-not-at-the-end'],
|
||||
['-but-not-at-the-end-', 'but-not-at-the-end'],
|
||||
['--_but-not-at-the-end___', 'but-not-at-the-end'],
|
||||
[' also remove all spaces', 'alsoremoveallspaces'],
|
||||
['a«"«»()@+-/*=%\{}…~|&œ—<>[]^±_−÷×≠‰A', 'a-_'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataCleanAppId
|
||||
*/
|
||||
public function testCleanAppId(string $inputString, string $appid): void {
|
||||
$this->assertEquals($appid, $this->manager->cleanAppId($inputString));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue