[tag_edit] abort on error rather than only applying some tags
This commit is contained in:
parent
acd3abcc77
commit
4b8bc82ee4
2 changed files with 16 additions and 16 deletions
|
@ -524,24 +524,21 @@ class Image
|
|||
{
|
||||
global $cache, $database, $page;
|
||||
|
||||
$unfiltered_tags = array_unique($unfiltered_tags);
|
||||
$tags = array_unique($unfiltered_tags);
|
||||
|
||||
$tags = [];
|
||||
foreach ($unfiltered_tags as $tag) {
|
||||
foreach ($tags as $tag) {
|
||||
if (mb_strlen($tag, 'UTF-8') > 255) {
|
||||
$page->flash("Can't set a tag longer than 255 characters");
|
||||
continue;
|
||||
throw new TagSetException("Can't set a tag longer than 255 characters");
|
||||
}
|
||||
if (str_starts_with($tag, "-")) {
|
||||
$page->flash("Can't set a tag which starts with a minus");
|
||||
continue;
|
||||
throw new TagSetException("Can't set a tag which starts with a minus");
|
||||
}
|
||||
if (str_contains($tag, "*")) {
|
||||
throw new TagSetException("Can't set a tag which contains a wildcard (*)");
|
||||
}
|
||||
|
||||
$tags[] = $tag;
|
||||
}
|
||||
|
||||
if (count($tags) <= 0) {
|
||||
throw new SCoreException('Tried to set zero tags');
|
||||
throw new TagSetException('Tried to set zero tags');
|
||||
}
|
||||
|
||||
if (strtolower(Tag::implode($tags)) != strtolower($this->get_tag_list())) {
|
||||
|
|
|
@ -28,12 +28,15 @@ class TagEditTest extends ShimmiePHPUnitTestCase
|
|||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
|
||||
$image = Image::by_id($image_id);
|
||||
|
||||
try {
|
||||
$e = $this->assertException(TagSetException::class, function () use ($image) {
|
||||
send_event(new TagSetEvent($image, []));
|
||||
$this->fail();
|
||||
} catch (SCoreException $e) {
|
||||
$this->assertEquals("Tried to set zero tags", $e->error);
|
||||
}
|
||||
});
|
||||
$this->assertEquals("Tried to set zero tags", $e->getMessage());
|
||||
|
||||
$e = $this->assertException(TagSetException::class, function () use ($image) {
|
||||
send_event(new TagSetEvent($image, ["*test*"]));
|
||||
});
|
||||
$this->assertEquals("Can't set a tag which contains a wildcard (*)", $e->getMessage());
|
||||
}
|
||||
|
||||
public function testTagEdit_tooLong()
|
||||
|
|
Reference in a new issue