diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index 650799b4a..ee57bb611 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -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 diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 712d723a7..29a6120f8 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -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")