diff --git a/lib/edn/string_transformer.rb b/lib/edn/string_transformer.rb index d8f8901..2a23ad3 100644 --- a/lib/edn/string_transformer.rb +++ b/lib/edn/string_transformer.rb @@ -23,6 +23,7 @@ module StringTransformer def self.parse_string(string) string = string.to_s return '' if string.empty? + string.force_encoding Encoding::ASCII_8BIT string = string.gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c| #" Clear messed up syntax highlighting with Emacs. if u = UNESCAPE_MAP[$&[1]] diff --git a/spec/edn/transform_spec.rb b/spec/edn/transform_spec.rb index 2cbe755..b390d50 100644 --- a/spec/edn/transform_spec.rb +++ b/spec/edn/transform_spec.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'spec_helper' describe EDN::Transform do @@ -26,6 +27,12 @@ subject.apply(:string => 'hello\n#{world}').should == "hello\n\#{world}" end end + + context "string-utf8" do + it "should emit a string that preserves utf-8 characters" do + subject.apply(:string => 'öhai world').should == "öhai world" + end + end context "keyword" do it "should emit a Ruby symbol" do