Fix #5346: Can add tags beginning with newpool:, causing the next edit to add the post to a pool.

This commit is contained in:
evazion
2022-11-12 17:01:52 -06:00
parent 86669fa605
commit 220db642e1
2 changed files with 12 additions and 1 deletions

View File

@@ -41,7 +41,7 @@ class TagNameValidator < ActiveModel::EachValidator
record.errors.add(attribute, "'#{value}' must consist of only ASCII characters")
when /\A(#{PostQueryBuilder::METATAGS.join("|")}):(.+)\z/i
record.errors.add(attribute, "'#{value}' cannot begin with '#{$1}:'")
when /\A(#{Tag.categories.regexp}):(.+)\z/i
when /\A(#{PostEdit::METATAGS.join("|")}):(.+)\z/i
record.errors.add(attribute, "'#{value}' cannot begin with '#{$1}:'")
when "new", "search", "and", "or", "not"
record.errors.add(attribute, "'#{value}' is a reserved name and cannot be used")

View File

@@ -481,6 +481,9 @@ class PostTest < ActiveSupport::TestCase
assert_invalid_tag("foo\abar")
assert_invalid_tag("café")
assert_invalid_tag("東方")
assert_invalid_tag("gen:char:foo")
assert_invalid_tag("general:newpool:a")
assert_invalid_tag("general:rating:g")
end
context "that already exists" do
@@ -604,6 +607,14 @@ class PostTest < ActiveSupport::TestCase
assert_equal(["tagme"], post.tag_array)
assert_equal(false, Tag.exists?(name: "copy:blah"))
end
should "not raise an exception for char:newpool:blah" do
post = create(:post, tag_string: "tagme char:newpool:blah")
assert_match(/Couldn't add tag: 'newpool:blah' cannot begin with 'newpool:'/, post.warnings[:base].join("\n"))
assert_equal(["tagme"], post.tag_array)
assert_equal(false, Tag.exists?(name: "newpool:blah"))
end
end
context "for a wildcard implication" do