Fix #3928: fix case sensitivity in metatags.

This commit is contained in:
evazion 2018-09-27 23:42:30 -05:00
parent 6a375d04e0
commit 984cd0432c
3 changed files with 7 additions and 4 deletions

View File

@ -21,7 +21,7 @@ class TagNameValidator < ActiveModel::EachValidator
record.errors[attribute] << "'#{value}' cannot contain non-printable characters"
when /[^[[:ascii:]]]/
record.errors[attribute] << "'#{value}' must consist of only ASCII characters"
when /\A(#{Regexp.union(Tag::METATAGS)}):(.+)\z/i
when /\A(#{Tag::METATAGS.join("|")}):(.+)\z/i
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"
when /\A(#{Tag.categories.regexp}):(.+)\z/i
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"

View File

@ -438,7 +438,7 @@ class Tag < ApplicationRecord
end
def is_metatag?(tag)
tag.match?(/\A(#{Regexp.union(METATAGS)}):(.+)\z/i)
has_metatag?(tag, *METATAGS)
end
def is_negated_tag?(tag)
@ -457,7 +457,7 @@ class Tag < ApplicationRecord
return nil if tags.blank?
tags = scan_query(tags.to_str) if tags.respond_to?(:to_str)
tags.grep(/\A#{Regexp.union(metatags.map(&:to_s))}:(.+)\z/i) { $1 }.first
tags.grep(/\A(?:#{metatags.map(&:to_s).join("|")}):(.+)\z/i) { $1 }.first
end
def parse_query(query, options = {})
@ -474,7 +474,7 @@ class Tag < ApplicationRecord
scan_query(query).each do |token|
q[:tag_count] += 1 unless Danbooru.config.is_unlimited_tag?(token)
if token =~ /\A(#{Regexp.union(METATAGS)}):(.+)\z/i
if token =~ /\A(#{METATAGS.join("|")}):(.+)\z/i
g1 = $1.downcase
g2 = $2
case g1

View File

@ -138,6 +138,7 @@ class TagTest < ActiveSupport::TestCase
assert_equal([:lte, 2], Tag.parse_query("id:..2")[:post_id])
assert_equal([:gt, 2], Tag.parse_query("id:>2")[:post_id])
assert_equal([:lt, 3], Tag.parse_query("id:<3")[:post_id])
assert_equal([:lt, 3], Tag.parse_query("ID:<3")[:post_id])
Tag.expects(:normalize_tags_in_query).returns(nil)
assert_equal(["acb"], Tag.parse_query("a*b")[:tags][:include])
@ -160,6 +161,7 @@ class TagTest < ActiveSupport::TestCase
assert_equal(false, Tag.is_simple_tag?("~foo"))
assert_equal(false, Tag.is_simple_tag?("foo*"))
assert_equal(false, Tag.is_simple_tag?("fav:1234"))
assert_equal(false, Tag.is_simple_tag?("FAV:1234"))
assert_equal(false, Tag.is_simple_tag?("pool:1234"))
assert_equal(false, Tag.is_simple_tag?('source:"foo bar baz"'))
assert_equal(false, Tag.is_simple_tag?("foo bar"))
@ -241,6 +243,7 @@ class TagTest < ActiveSupport::TestCase
should_not allow_value("foo\abar").for(:name).on(:create)
should_not allow_value("café").for(:name).on(:create)
should_not allow_value("東方").for(:name).on(:create)
should_not allow_value("FAV:blah").for(:name).on(:create)
metatags = Tag::METATAGS + TagCategory.mapping.keys
metatags.each do |metatag|