diff --git a/CHANGELOG.md b/CHANGELOG.md index 12c7c4cd2..cb987d50f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch. * Breaking Changes * Features * Fixes + * [Fix breaking encoding of tag](https://github.com/mbleigh/acts-as-taggable-on/pull/456) * Misc ### [3.0.0 / 2014-01-01](https://github.com/mbleigh/acts-as-taggable-on/compare/v2.4.1...v3.0.0) 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