Browse Source

Merge pull request #55142 from nextcloud/fix/allow-hyphen-in-appid

fix: Allow hyphen in appid
pull/53919/head
Côme Chilliet 2 months ago
committed by GitHub
parent
commit
7e0cda995a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      lib/private/App/AppManager.php
  2. 30
      tests/lib/App/AppManagerTest.php

2
lib/private/App/AppManager.php

@ -1021,7 +1021,7 @@ 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);
}
/**

30
tests/lib/App/AppManagerTest.php

@ -28,6 +28,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\ServerVersion;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@ -143,7 +144,7 @@ class AppManagerTest extends TestCase {
);
}
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppIcon')]
#[DataProvider('dataGetAppIcon')]
public function testGetAppIcon($callback, ?bool $dark, ?string $expected): void {
$this->urlGenerator->expects($this->atLeastOnce())
->method('imagePath')
@ -314,7 +315,7 @@ class AppManagerTest extends TestCase {
/**
* @param array $appInfo
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataEnableAppForGroupsAllowedTypes')]
#[DataProvider('dataEnableAppForGroupsAllowedTypes')]
public function testEnableAppForGroupsAllowedTypes(array $appInfo): void {
$group1 = $this->createMock(IGroup::class);
$group1->method('getGID')
@ -375,7 +376,7 @@ class AppManagerTest extends TestCase {
* @param string $type
*
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataEnableAppForGroupsForbiddenTypes')]
#[DataProvider('dataEnableAppForGroupsForbiddenTypes')]
public function testEnableAppForGroupsForbiddenTypes($type): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('test can\'t be enabled for groups.');
@ -781,7 +782,7 @@ class AppManagerTest extends TestCase {
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('isBackendRequiredDataProvider')]
#[DataProvider('isBackendRequiredDataProvider')]
public function testIsBackendRequired(
string $backend,
array $appBackends,
@ -896,4 +897,25 @@ class AppManagerTest extends TestCase {
$manager->getAppVersion('unknown'),
);
}
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…
Cancel
Save