tags: don't allow tags to begin with a '/'.
Disallow tags from starting with a '/' character. This is so that tag
abbreviations in autocomplete, which start with a '/', don't conflict
with regular tags.
Also disallow some other punctuation characters: `%{})]. Currently no
tags start with these characters. This is to reserve other special
characters in case we need them for other future syntax extensions.
This commit is contained in:
@@ -7,12 +7,8 @@ class TagNameValidator < ActiveModel::EachValidator
|
||||
record.errors.add(attribute, "'#{value}' cannot contain asterisks ('*')")
|
||||
when /,/
|
||||
record.errors.add(attribute, "'#{value}' cannot contain commas (',')")
|
||||
when /\A~/
|
||||
record.errors.add(attribute, "'#{value}' cannot begin with a tilde ('~')")
|
||||
when /\A-/
|
||||
record.errors.add(attribute, "'#{value}' cannot begin with a dash ('-')")
|
||||
when /\A_/
|
||||
record.errors.add(attribute, "'#{value}' cannot begin with an underscore")
|
||||
when /\A[-~_`%){}\]\/]/
|
||||
record.errors.add(attribute, "'#{value}' cannot begin with a '#{value[0]}'")
|
||||
when /_\z/
|
||||
record.errors.add(attribute, "'#{value}' cannot end with an underscore")
|
||||
when /__/
|
||||
|
||||
@@ -97,16 +97,6 @@ class AutocompleteServiceTest < ActiveSupport::TestCase
|
||||
assert_autocomplete_includes("mole_under_eye", "-/mue", :tag_query)
|
||||
assert_autocomplete_includes("mole_under_eye", "~/mue", :tag_query)
|
||||
end
|
||||
|
||||
should "work for regular tags starting with a /" do
|
||||
create(:tag, name: "jojo_pose", post_count: 100)
|
||||
create(:tag, name: "/jp/", post_count: 50)
|
||||
|
||||
assert_autocomplete_equals(%w[/jp/ jojo_pose], "/", :tag_query)
|
||||
assert_autocomplete_equals(%w[/jp/ jojo_pose], "/j", :tag_query)
|
||||
assert_autocomplete_equals(%w[/jp/ jojo_pose], "/jp", :tag_query)
|
||||
assert_autocomplete_equals(%w[/jp/], "/jp/", :tag_query)
|
||||
end
|
||||
end
|
||||
|
||||
should "autocomplete tags from wiki and artist other names" do
|
||||
|
||||
@@ -169,6 +169,13 @@ class TagTest < ActiveSupport::TestCase
|
||||
should_not allow_value("___").for(:name).on(:create)
|
||||
should_not allow_value("~foo").for(:name).on(:create)
|
||||
should_not allow_value("-foo").for(:name).on(:create)
|
||||
should_not allow_value("/foo").for(:name).on(:create)
|
||||
should_not allow_value("`foo").for(:name).on(:create)
|
||||
should_not allow_value("%foo").for(:name).on(:create)
|
||||
should_not allow_value(")foo").for(:name).on(:create)
|
||||
should_not allow_value("{foo").for(:name).on(:create)
|
||||
should_not allow_value("}foo").for(:name).on(:create)
|
||||
should_not allow_value("]foo").for(:name).on(:create)
|
||||
should_not allow_value("_foo").for(:name).on(:create)
|
||||
should_not allow_value("foo_").for(:name).on(:create)
|
||||
should_not allow_value("foo__bar").for(:name).on(:create)
|
||||
|
||||
Reference in New Issue
Block a user