Fix #3272: Unicode tags are still being allowed.

* Don't allow adding tags with invalid names when they already exist in
  the tags table.
* If an invalid tag is added, show an warning and ignore the tag instead
  of failing with a hard error.
* Move the _(cosplay) tag validation into the tag name validator.
This commit is contained in:
evazion
2019-08-15 16:41:27 -05:00
parent e85c6c3250
commit b9d35eaf2c
5 changed files with 76 additions and 63 deletions

View File

@@ -17,14 +17,21 @@ class TagNameValidator < ActiveModel::EachValidator
record.errors[attribute] << "'#{value}' cannot end with an underscore"
when /__/
record.errors[attribute] << "'#{value}' cannot contain consecutive underscores"
when /[^[[:graph:]]]/
when /[^[:graph:]]/
record.errors[attribute] << "'#{value}' cannot contain non-printable characters"
when /[^[[:ascii:]]]/
when /[^[:ascii:]]/
record.errors[attribute] << "'#{value}' must consist of only ASCII characters"
when /\A(#{Tag::METATAGS.join("|")}):(.+)\z/i
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"
when /\A(#{Tag.categories.regexp}):(.+)\z/i
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"
when /\A(.+)_\(cosplay\)\z/i
tag_name = TagAlias.to_aliased([$1]).first
tag = Tag.find_by_name(tag_name)
if tag.present? && tag.category != Tag.categories.character
record.errors[attribute] << "#{tag_name} must be a character tag"
end
end
end
end