Skip to content

Commit

Permalink
Properly get one-byte bytelists from cache when indexing with byte
Browse files Browse the repository at this point in the history
Fixes #1361.
  • Loading branch information
headius committed Feb 21, 2014
1 parent 669017a commit 9cb8243
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -7338,7 +7338,7 @@ private IRubyObject each_charCommon19(ThreadContext context, Block block) {
int n = is7bit ? 1 : StringSupport.length(enc, bytes, p, end);
RubyString str;
if (n == 1 && isUSASCII) {
str = newStringShared(runtime, RubyFixnum.SINGLE_CHAR_BYTELISTS19[bytes[p]], StringSupport.CR_7BIT);
str = newStringShared(runtime, RubyFixnum.SINGLE_CHAR_BYTELISTS19[bytes[p] & 0xFF], StringSupport.CR_7BIT);
} else {
str = makeShared19(runtime, val, p-value.getBegin(), n);
}
Expand Down
@@ -0,0 +1,10 @@
describe "An ASCII string with high-range bytes" do
it "can each_char through the high bytes successfully" do
ary = []
str = "M\xA1xico".force_encoding("ASCII")
str.each_char {|c| ary << c}

expect(ary.length).to eq 6
expect(ary).to eq(['M', "\xA1", 'x', 'i', 'c', 'o'])
end
end unless RUBY_VERSION < '1.9'

0 comments on commit 9cb8243

Please sign in to comment.