From 383c377aff94b409d6addf36116dca03763cafc1 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Wed, 8 Jan 2014 14:24:26 +0900 Subject: [PATCH] fix as_8bit_ascii changes argument's encoding --- lib/acts_as_taggable_on/tag.rb | 2 +- spec/acts_as_taggable_on/tag_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/acts_as_taggable_on/tag.rb b/lib/acts_as_taggable_on/tag.rb index b3727dbf7..d30a0a8fe 100644 --- a/lib/acts_as_taggable_on/tag.rb +++ b/lib/acts_as_taggable_on/tag.rb @@ -113,7 +113,7 @@ def binary def as_8bit_ascii(string) if defined?(Encoding) - string.to_s.force_encoding('BINARY') + string.to_s.dup.force_encoding('BINARY') else string.to_s.mb_chars end diff --git a/spec/acts_as_taggable_on/tag_spec.rb b/spec/acts_as_taggable_on/tag_spec.rb index 01a7df289..cac682507 100644 --- a/spec/acts_as_taggable_on/tag_spec.rb +++ b/spec/acts_as_taggable_on/tag_spec.rb @@ -194,6 +194,13 @@ ActsAsTaggableOn::Tag.named('cool').should include(@tag) ActsAsTaggableOn::Tag.named('cool').should_not include(uppercase_tag) end + + it "should not change enconding" do + name = "\u3042" + original_encoding = name.encoding + ActsAsTaggableOn::Tag.find_or_create_with_like_by_name(name) + name.encoding.should == original_encoding + end end describe "name uniqeness validation" do