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:
evazion
2020-12-17 13:17:55 -06:00
parent 7a87225ac8
commit 1809f67b2b
3 changed files with 9 additions and 16 deletions

View File

@@ -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 /__/

View File

@@ -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

View File

@@ -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)