Skip to content

Commit

Permalink
Merge pull request #3437 from k77ch7/fix_GH-3402
Browse files Browse the repository at this point in the history
Fix for issue 3402: String#encode with :replace option does not return correct value
  • Loading branch information
kares committed Nov 20, 2015
2 parents 0f12e47 + e59bad4 commit 2b82638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/EncodingUtils.java
Expand Up @@ -879,7 +879,7 @@ public static Encoding strTranscode0(ThreadContext context, int argc, IRubyObjec
if ((ecflags & EConvFlags.INVALID_MASK) != 0 && explicitlyInvalidReplace) {
IRubyObject rep = context.nil;
if (!ecopts.isNil()) {
rep = ((RubyHash)ecopts).op_aref(context, runtime.newString("replace"));
rep = ((RubyHash)ecopts).op_aref(context, runtime.newSymbol("replace"));
}
dest = ((RubyString)str).scrub(context, rep, Block.NULL_BLOCK);
if (dest.isNil()) dest = str;
Expand Down
12 changes: 12 additions & 0 deletions spec/regression/GH-3402_spec.rb
@@ -0,0 +1,12 @@
# coding: utf-8

require 'rspec'

# https://github.com/jruby/jruby/issues/3402
describe 'String#encode with :replace option' do
it 'returns correct value' do
str = "testing\xC2".encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "foo123")
expect(str).to eq "testingfoo123"
end
end

0 comments on commit 2b82638

Please sign in to comment.