diff --git a/app/logical/tag_name_validator.rb b/app/logical/tag_name_validator.rb index dfff576ca..7163ef85f 100644 --- a/app/logical/tag_name_validator.rb +++ b/app/logical/tag_name_validator.rb @@ -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") diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 448eb206f..4eafa3132 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -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