diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-02-27 11:49:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 11:49:50 +0100 |
commit | 70a68e88f56c67c39f5b06d7532704bd5fe7acf3 (patch) | |
tree | b4babc93f706eb37860c4ef6e03d10e1ee0a590e | |
parent | 15f660fa5f1b9cf52c29a66c1693462ca79459d0 (diff) | |
parent | 4f7d77406d71bc7af919adb20bc42ea7e861e3c9 (diff) | |
download | nextcloud-server-70a68e88f56c67c39f5b06d7532704bd5fe7acf3.tar.gz nextcloud-server-70a68e88f56c67c39f5b06d7532704bd5fe7acf3.zip |
Merge pull request #36837 from nextcloud/fix/truncate-overlong-tagnames
fix(SystemTagManager): Truncate overlong tag names
-rw-r--r-- | lib/private/SystemTag/SystemTagManager.php | 8 | ||||
-rw-r--r-- | tests/lib/SystemTag/SystemTagManagerTest.php | 13 |
2 files changed, 14 insertions, 7 deletions
diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index 4524aeaf7bc..79c5adcf450 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -193,10 +193,12 @@ class SystemTagManager implements ISystemTagManager { * {@inheritdoc} */ public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag { + // Length of name column is 64 + $truncatedTagName = substr($tagName, 0, 64); $query = $this->connection->getQueryBuilder(); $query->insert(self::TAG_TABLE) ->values([ - 'name' => $query->createNamedParameter($tagName), + 'name' => $query->createNamedParameter($truncatedTagName), 'visibility' => $query->createNamedParameter($userVisible ? 1 : 0), 'editable' => $query->createNamedParameter($userAssignable ? 1 : 0), ]); @@ -205,7 +207,7 @@ class SystemTagManager implements ISystemTagManager { $query->execute(); } catch (UniqueConstraintViolationException $e) { throw new TagAlreadyExistsException( - 'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists', + 'Tag ("' . $truncatedTagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists', 0, $e ); @@ -215,7 +217,7 @@ class SystemTagManager implements ISystemTagManager { $tag = new SystemTag( (string)$tagId, - $tagName, + $truncatedTagName, $userVisible, $userAssignable ); diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index ef0546dbd88..e261a68aaf7 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -259,6 +259,11 @@ class SystemTagManagerTest extends TestCase { $this->tagManager->createTag($name, $userVisible, $userAssignable); } + public function testCreateOverlongName() { + $tag = $this->tagManager->createTag('Zona circundante do Palácio Nacional da Ajuda (Jardim das Damas, Salão de Física, Torre Sineira, Paço Velho e Jardim Botânico)', true, true); + $this->assertSame('Zona circundante do Palácio Nacional da Ajuda (Jardim das Damas', $tag->getName()); // 63 characters but 64 bytes due to "á" + } + /** * @dataProvider oneTagMultipleFlagsProvider */ @@ -281,14 +286,14 @@ class SystemTagManagerTest extends TestCase { $this->assertSameTag($tag2, $tagList[$tag2->getId()]); } - + public function testGetNonExistingTag() { $this->expectException(\OCP\SystemTag\TagNotFoundException::class); $this->tagManager->getTag('nonexist', false, false); } - + public function testGetNonExistingTagsById() { $this->expectException(\OCP\SystemTag\TagNotFoundException::class); @@ -296,7 +301,7 @@ class SystemTagManagerTest extends TestCase { $this->tagManager->getTagsByIds([$tag1->getId(), 100, 101]); } - + public function testGetInvalidTagIdFormat() { $this->expectException(\InvalidArgumentException::class); @@ -391,7 +396,7 @@ class SystemTagManagerTest extends TestCase { $this->assertEmpty($this->tagManager->getAllTags()); } - + public function testDeleteNonExistingTag() { $this->expectException(\OCP\SystemTag\TagNotFoundException::class); |