Skip to content

Commit

Permalink
Revert "improve postgres escape sequence"
Browse files Browse the repository at this point in the history
This reverts commit cc7a2c0.
  • Loading branch information
Kirill Shirinkin committed Jun 5, 2018
1 parent edc6180 commit 04c6658
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appraise 'activerecord-5.2' do
gem 'rails', '5.2.0'
gem 'activerecord', '5.2.0'
end

appraise 'activerecord-5.1' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def tags_match_type

def escaped_tag(tag)
tag = tag.downcase unless ActsAsTaggableOn.strict_case_match
ActsAsTaggableOn::Utils.escape_like(tag)
tag.gsub(/[!%_]/) { |x| '!' + x }
end

def adjust_taggings_alias(taggings_alias)
Expand Down
6 changes: 1 addition & 5 deletions lib/acts_as_taggable_on/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ def like_operator

# escape _ and % characters in strings, since these are wildcards in SQL.
def escape_like(str)
str.gsub(/[!%_]/) { |x| escape_replacement + x }
end

def escape_replacement
using_postgresql? ? '\\' : '!'
str.gsub(/[!%_]/) { |x| '!' + x }
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions spec/acts_as_taggable_on/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,4 @@
expect(ActsAsTaggableOn::Utils.sha_prefix('puppies')).not_to eq(ActsAsTaggableOn::Utils.sha_prefix('kittens'))
end
end

describe '#escape_replacement' do
it 'should return ! when the adapter is not PostgreSQL' do
allow(ActsAsTaggableOn::Utils.connection).to receive(:adapter_name) { 'MySQL' }
expect(ActsAsTaggableOn::Utils.escape_replacement).to eq('!')
end

it 'should return \\ when the adapter is PostgreSQL' do
allow(ActsAsTaggableOn::Utils.connection).to receive(:adapter_name) { 'PostgreSQL' }
expect(ActsAsTaggableOn::Utils.escape_replacement).to eq('\\')
end
end
end

0 comments on commit 04c6658

Please sign in to comment.