Update lib/sequel/plugins/string_stripper.rb #593

Closed
wants to merge 3 commits into
from
View
2 lib/sequel/plugins/string_stripper.rb
@@ -18,7 +18,7 @@ module InstanceMethods
# Strip value if it is a string, before attempting to assign
# it to the model's values.
def []=(k, v)
- v.is_a?(String) ? super(k, v.strip) : super
+ v.is_a?(String) ? super(k, (v.strip rescue v)) : super
end
end
end
View
7 spec/extensions/string_stripper_spec.rb
@@ -1,3 +1,5 @@
+#encoding: utf-8
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
describe "Sequel::Plugins::StringStripper" do
@@ -13,6 +15,11 @@
@o.name = ' name '
@o.name.should == 'name'
end
+
+ it "should gracefully ignore non UTF-8 strings" do
+ @o.name = " \xEF"
+ @o.name.should == " \xEF"
+ end
it "should not affect other types" do
@o.name = 1