Merge pull request #3389 from evazion/fix-3387

Fix #3387: Safebooru: Two tag searches fail for members.
This commit is contained in:
Albert Yi
2017-11-20 11:39:50 -08:00
committed by GitHub
3 changed files with 23 additions and 1 deletions

View File

@@ -427,7 +427,7 @@ class Tag < ApplicationRecord
}
scan_query(query).each do |token|
q[:tag_count] += 1 unless token == "status:deleted" || token =~ /\Alimit:.+\Z/
q[:tag_count] += 1 unless Danbooru.config.is_unlimited_tag?(token)
if token =~ /\A(#{METATAGS}):(.+)\Z/i
g1 = $1.downcase

View File

@@ -169,6 +169,11 @@ module Danbooru
end
end
# Return true if the given tag shouldn't count against the user's tag search limit.
def is_unlimited_tag?(tag)
!!(tag =~ /\A(-?status:deleted|rating:s.*|limit:.+)\z/i)
end
# After this many pages, the paginator will switch to sequential mode.
def max_numbered_pages
1_000

View File

@@ -2292,6 +2292,14 @@ class PostTest < ActiveSupport::TestCase
end
end
should "not count free tags against the user's search limit" do
post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s")
Danbooru.config.expects(:is_unlimited_tag?).with("rating:s").once.returns(true)
Danbooru.config.expects(:is_unlimited_tag?).with(anything).twice.returns(false)
assert_tag_match([post1], "aaa bbb rating:s")
end
should "succeed for exclusive tag searches with no other tag" do
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
assert_nothing_raised do
@@ -2425,6 +2433,15 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, Post.fast_count(""))
end
should "not fail for a two tag search by a member" do
post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s")
post2 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:e")
Danbooru.config.expects(:is_unlimited_tag?).with("rating:s").once.returns(true)
Danbooru.config.expects(:is_unlimited_tag?).with(anything).twice.returns(false)
assert_equal(1, Post.fast_count("aaa bbb"))
end
should "set the value in cache" do
Post.expects(:set_count_in_cache).with("rating:s", kind_of(Integer)).once
Post.fast_count("")