This commit is contained in:
albert
2013-03-08 13:44:34 -05:00
parent 41f7e2a804
commit 8f65b567a2
2 changed files with 29 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ module Danbooru
end
def to_escaped_for_tsquery
"'#{gsub(/\\|'/, '\0\0\0\0')}'"
"'#{gsub(/'/, '\0\0').gsub(/\\/, '\0\0\0\0')}'"
end
def to_escaped_js

View File

@@ -757,6 +757,34 @@ class PostTest < ActiveSupport::TestCase
end
context "Searching:" do
should "return posts for the ' tag" do
post1 = FactoryGirl.create(:post, :tag_string => "'")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("'").count
assert_equal(1, count)
end
should "return posts for the \\ tag" do
post1 = FactoryGirl.create(:post, :tag_string => "\\")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("\\").count
assert_equal(1, count)
end
should "return posts for the ( tag" do
post1 = FactoryGirl.create(:post, :tag_string => "(")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("(").count
assert_equal(1, count)
end
should "return posts for the ? tag" do
post1 = FactoryGirl.create(:post, :tag_string => "?")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("?").count
assert_equal(1, count)
end
should "return posts for 1 tag" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")