Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/private/SystemTag/SystemTagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ public function getTag(string $tagName, bool $userVisible, bool $userAssignable)
* {@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),
]);
Expand All @@ -205,7 +207,7 @@ public function createTag(string $tagName, bool $userVisible, bool $userAssignab
$query->execute();
} catch (UniqueConstraintViolationException $e) {
throw new TagAlreadyExistsException(
'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists',
'Tag ("' . $truncatedTagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists',
0,
$e
);
Expand All @@ -215,7 +217,7 @@ public function createTag(string $tagName, bool $userVisible, bool $userAssignab

$tag = new SystemTag(
(string)$tagId,
$tagName,
$truncatedTagName,
$userVisible,
$userAssignable
);
Expand Down
13 changes: 9 additions & 4 deletions tests/lib/SystemTag/SystemTagManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public function testCreateDuplicate($name, $userVisible, $userAssignable) {
$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
*/
Expand All @@ -281,22 +286,22 @@ public function testGetExistingTagById() {
$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);

$tag1 = $this->tagManager->createTag('one', true, false);
$this->tagManager->getTagsByIds([$tag1->getId(), 100, 101]);
}


public function testGetInvalidTagIdFormat() {
$this->expectException(\InvalidArgumentException::class);

Expand Down Expand Up @@ -391,7 +396,7 @@ public function testDeleteTags() {
$this->assertEmpty($this->tagManager->getAllTags());
}


public function testDeleteNonExistingTag() {
$this->expectException(\OCP\SystemTag\TagNotFoundException::class);

Expand Down