block tags starting with minus

This commit is contained in:
Shish 2018-08-22 21:56:27 +01:00
parent 4da207106b
commit 38406ef33a

View file

@ -581,11 +581,21 @@ class Image {
/** /**
* Set the tags for this image. * Set the tags for this image.
*
* @param string[] $tags
* @throws Exception
*/ */
public function set_tags(array $tags) { public function set_tags(array $unfiltered_tags) {
$tags = [];
foreach ($unfiltered_tags as $tag) {
if(mb_strlen($tag, 'UTF-8') > 255){
flash_message("Can't set a tag longer than 255 characters");
continue;
}
if(startsWith($tag, "-")) {
flash_message("Can't set a tag which starts with a minus");
continue;
}
$tags[] = $tag;
}
assert('count($tags) > 0', var_export($tags, true)); assert('count($tags) > 0', var_export($tags, true));
global $database; global $database;
@ -598,11 +608,6 @@ class Image {
$this->delete_tags_from_image(); $this->delete_tags_from_image();
// insert each new tags // insert each new tags
foreach($tags as $tag) { foreach($tags as $tag) {
if(mb_strlen($tag, 'UTF-8') > 255){
flash_message("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n");
continue;
}
$id = $database->get_one( $id = $database->get_one(
$database->scoreql_to_sql(" $database->scoreql_to_sql("
SELECT id SELECT id