tags: don't allow tags more than 170 chars long.
Limit tag length to 170 chars. 170 chars was chosen because it's longer than the longest active tag on Danbooru. Tag length is limited because in some contexts we can't deal with excessively long tags. Tag autocorrect for example uses the levenshtein function in Postgres, which can't handle strings more than 255 chars long.
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
class TagNameValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
case Tag.normalize_name(value)
|
||||
value = Tag.normalize_name(value)
|
||||
|
||||
if value.size > 170
|
||||
record.errors.add(attribute, "'#{value}' cannot be more than 255 characters long")
|
||||
end
|
||||
|
||||
case value
|
||||
when /\A_*\z/
|
||||
record.errors.add(attribute, "'#{value}' cannot be blank")
|
||||
when /\*/
|
||||
|
||||
@@ -185,6 +185,7 @@ class TagTest < ActiveSupport::TestCase
|
||||
should_not allow_value("café").for(:name).on(:create)
|
||||
should_not allow_value("東方").for(:name).on(:create)
|
||||
should_not allow_value("FAV:blah").for(:name).on(:create)
|
||||
should_not allow_value("X"*171).for(:name).on(:create)
|
||||
|
||||
metatags = PostQueryBuilder::METATAGS + TagCategory.mapping.keys
|
||||
metatags.each do |metatag|
|
||||
|
||||
Reference in New Issue
Block a user