Fix #3928: fix case sensitivity in metatags.
This commit is contained in:
@@ -21,7 +21,7 @@ class TagNameValidator < ActiveModel::EachValidator
|
|||||||
record.errors[attribute] << "'#{value}' cannot contain non-printable characters"
|
record.errors[attribute] << "'#{value}' cannot contain non-printable characters"
|
||||||
when /[^[[:ascii:]]]/
|
when /[^[[:ascii:]]]/
|
||||||
record.errors[attribute] << "'#{value}' must consist of only ASCII characters"
|
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}:'"
|
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"
|
||||||
when /\A(#{Tag.categories.regexp}):(.+)\z/i
|
when /\A(#{Tag.categories.regexp}):(.+)\z/i
|
||||||
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"
|
record.errors[attribute] << "'#{value}' cannot begin with '#{$1}:'"
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def is_metatag?(tag)
|
def is_metatag?(tag)
|
||||||
tag.match?(/\A(#{Regexp.union(METATAGS)}):(.+)\z/i)
|
has_metatag?(tag, *METATAGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_negated_tag?(tag)
|
def is_negated_tag?(tag)
|
||||||
@@ -457,7 +457,7 @@ class Tag < ApplicationRecord
|
|||||||
return nil if tags.blank?
|
return nil if tags.blank?
|
||||||
|
|
||||||
tags = scan_query(tags.to_str) if tags.respond_to?(:to_str)
|
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
|
end
|
||||||
|
|
||||||
def parse_query(query, options = {})
|
def parse_query(query, options = {})
|
||||||
@@ -474,7 +474,7 @@ class Tag < ApplicationRecord
|
|||||||
scan_query(query).each do |token|
|
scan_query(query).each do |token|
|
||||||
q[:tag_count] += 1 unless Danbooru.config.is_unlimited_tag?(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
|
g1 = $1.downcase
|
||||||
g2 = $2
|
g2 = $2
|
||||||
case g1
|
case g1
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ class TagTest < ActiveSupport::TestCase
|
|||||||
assert_equal([:lte, 2], Tag.parse_query("id:..2")[:post_id])
|
assert_equal([:lte, 2], Tag.parse_query("id:..2")[:post_id])
|
||||||
assert_equal([:gt, 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])
|
||||||
|
assert_equal([:lt, 3], Tag.parse_query("ID:<3")[:post_id])
|
||||||
|
|
||||||
Tag.expects(:normalize_tags_in_query).returns(nil)
|
Tag.expects(:normalize_tags_in_query).returns(nil)
|
||||||
assert_equal(["acb"], Tag.parse_query("a*b")[:tags][:include])
|
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?("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?("FAV:1234"))
|
||||||
assert_equal(false, Tag.is_simple_tag?("pool: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?('source:"foo bar baz"'))
|
||||||
assert_equal(false, Tag.is_simple_tag?("foo bar"))
|
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("foo\abar").for(:name).on(:create)
|
||||||
should_not allow_value("café").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("東方").for(:name).on(:create)
|
||||||
|
should_not allow_value("FAV:blah").for(:name).on(:create)
|
||||||
|
|
||||||
metatags = Tag::METATAGS + TagCategory.mapping.keys
|
metatags = Tag::METATAGS + TagCategory.mapping.keys
|
||||||
metatags.each do |metatag|
|
metatags.each do |metatag|
|
||||||
|
|||||||
Reference in New Issue
Block a user