Permalink
Browse files

[encoding] [jruby] add a spec to make sure that ascii substrings of b…

…inary string can be utf-8 encoded without an exception in jruby
  • Loading branch information...
1 parent ef58f10 commit 34bf4d35faac8a58da2ea5f061f90b1e2347a7e8 John Shahid committed Jul 8, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 core/string/encoding_spec.rb
@@ -67,6 +67,16 @@
"\u{4040}".encoding.should == Encoding::UTF_8
end
+ it "an ascii substring of a binary string should be encoded UTF-8 without raising an exception" do
+ binary_string = "\x82foo"
+ ascii_string = binary_string.bytes.to_a.pack('c*')[1..-1]
+ ascii_string.should == "foo"
+ ascii_string.encoding.name.should == "ASCII-8BIT"
+ utf8_string = ascii_string.encode("UTF-8")
+ utf8_string.should == "foo"
+ utf8_string.encoding.name.should == "UTF-8"
+ end
+
it "returns US-ASCII if self is US-ASCII only" do
s = "\u{40}"
s.ascii_only?.should be_true

0 comments on commit 34bf4d3

Please sign in to comment.