Skip to content

Commit 01f3945

Browse files
committed
Merge branch 'test-fix-2419' into jruby-1_7
2 parents dbf58e6 + ff54579 commit 01f3945

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

core/src/main/java/org/jruby/util/encoding/CharsetTranscoder.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,21 @@ public RubyCoderResult transcode(ThreadContext context, ByteList value, ByteList
235235

236236
return transcode(context, value, dest, fromEncoding, false, true);
237237
}
238-
238+
239+
public RubyCoderResult econvConvert(ThreadContext context, ByteList inBuffer, ByteList outBuffer) {
240+
Encoding fromEncoding = this.inEncoding != null ? this.inEncoding : inBuffer.getEncoding();
241+
242+
primitiveConvert(context, inBuffer.shallowDup(), outBuffer, 0, -1, fromEncoding, false, actions.ecflags);
243+
244+
if (lastResult != null) {
245+
createLastError();
246+
} else {
247+
outBuffer.append(finish(inBuffer.getEncoding()));
248+
}
249+
250+
return lastResult;
251+
}
252+
239253
public ByteList transcode(ThreadContext context, ByteList value) {
240254
ByteList dest = new ByteList();
241255

core/src/main/java/org/jruby/util/encoding/Transcoder.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ public static ByteList strConvEncOpts(ThreadContext context, ByteList value, Enc
149149

150150
Transcoder ec = EncodingUtils.econvOpenOpts(context, fromEncoding.getName(), toEncoding.getName(), ecflags, ecopts);
151151
if (ec == null) return value;
152-
153-
ByteList ret = ec.convert(context, value, false);
154-
155-
ret.setEncoding(toEncoding);
156-
157-
return ret;
152+
153+
ByteList newStr = new ByteList();
154+
RubyCoderResult ret = ec.econvConvert(context, value, newStr);
155+
156+
if (ret == null || ret.stringResult.equals("finished")) {
157+
newStr.setEncoding(toEncoding);
158+
return newStr;
159+
} else {
160+
// error result, failover to original
161+
return value;
162+
}
158163
}
159164

160165
// rb_str_conv_enc
@@ -187,6 +192,8 @@ public static ByteList transcode(ThreadContext context, ByteList value, Encoding
187192

188193
// rb_econv_convert
189194
public abstract RubyCoderResult transcode(ThreadContext context, ByteList value, ByteList dest);
195+
196+
public abstract RubyCoderResult econvConvert(ThreadContext context, ByteList value, ByteList dest);
190197

191198
public abstract ByteList transcode(ThreadContext context, ByteList value);
192199

0 commit comments

Comments
 (0)