tags: don't allow tags with unbalanced parentheses.
Don't allow tags to have unbalanced parentheses, except for a few emoticon tags as special exceptions to the rule.
This commit is contained in:
@@ -18,6 +18,10 @@ class TagNameValidator < ActiveModel::EachValidator
|
||||
record.errors.add(attribute, "'#{value}' cannot be more than #{MAX_TAG_LENGTH} characters long")
|
||||
end
|
||||
|
||||
if !value.in?(Tag::PERMITTED_UNBALANCED_TAGS) && !value.has_balanced_parens?
|
||||
record.errors.add(attribute, "'#{value}' cannot have unbalanced parentheses")
|
||||
end
|
||||
|
||||
case value
|
||||
when /\A_*\z/
|
||||
record.errors.add(attribute, "cannot be blank")
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
class Tag < ApplicationRecord
|
||||
ABBREVIATION_REGEXP = /([a-z0-9])[a-z0-9']*($|[^a-z0-9']+)/
|
||||
|
||||
# Tags that are permitted to have unbalanced parentheses, as a special exception to the normal rule that parentheses in tags must balanced.
|
||||
PERMITTED_UNBALANCED_TAGS = %w[:) :( ;) ;( >:) >:(]
|
||||
|
||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||
has_one :artist, :foreign_key => "name", :primary_key => "name"
|
||||
has_one :antecedent_alias, -> {active}, :class_name => "TagAlias", :foreign_key => "antecedent_name", :primary_key => "name"
|
||||
|
||||
Reference in New Issue
Block a user