Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 344ffb4a27e2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c28f62a2d877
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on May 12, 2016

  1. Copy the full SHA
    bc9df5f View commit details
  2. Also check content of encoded File.basename result.

    Triggers bug discovered by @ahorek here:
    
    d025e43#commitcomment-17451035
    headius committed May 12, 2016
    Copy the full SHA
    e3b8e8c View commit details
  3. Copy the full SHA
    c28f62a View commit details
Showing with 30 additions and 9 deletions.
  1. +27 −7 core/src/main/java/org/jruby/util/io/EncodingUtils.java
  2. +3 −2 spec/ruby/core/file/basename_spec.rb
34 changes: 27 additions & 7 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -939,7 +939,8 @@ public static Encoding strTranscode0(ThreadContext context, int argc, IRubyObjec
if (frompPos.p != sp.begin() + slen) {
throw runtime.newArgumentError("not fully converted, " + (slen - frompPos.p) + " bytes left");
}
destp.setRealSize(destpPos.p);

// MRI sets length of dest here, but we've already done it in the inner transcodeLoop

if (denc_p[0] == null) {
dencindex = defineDummyEncoding(context, dname_p[0]);
@@ -1302,21 +1303,38 @@ public static ByteList transcodeString(String string, Encoding toEncoding, int e
*
* The data in inBytes will be transcoded from the source encoding to the destination, eventually
* replacing the contents of the given ByteList. Along the way, invalid characters may be handled by
* calling the fallback function (if non-null) with the given state and data. If the target ByteList
* needs to be resized, use the given function to do so.
* calling the fallback function (if non-null) with the given state and data. If the destination
* needs to be resized, use the given function to do so. Upon completion, destination will
* contain the resulting transcoded bytes.
*
* MRI: transcode_loop generified with EConv and fallback function provided
*
* @param ec the encoding converter
* @param fallbackFunc the fallback function for non-transcodable characters, or null if none
* @param s runtime state to pass into the fallback
* @param fallbackData call state to pass into the fallback
* @param inBytes the incoming byte array
* @param inPos the position from which to start in the incoming bytearray
* @param outBytes the initial output byte array
* @param outPos the position from which to start in the initial output byte array
* @param inStop the position at which to stop in the input
* @param outStop the number of bytes at which to stop in the output
* @param destination the ByteList to hold the eventual output
* @param resizeFunction a function to use to grow the destination
* @param <State> type of state for the fallback function
* @param <Data> type of data for the fallback function
* @return
*/
public static <State,Data> boolean transcodeLoop(EConv ec, TranscodeFallback<State,Data> fallbackFunc, State s, Data fallbackData, byte[] inBytes, Ptr inPos, byte[] outBytes, Ptr outPos, int inStop, int _outStop, ByteList destination, ResizeFunction resizeFunction) {
Ptr outStop = new Ptr(_outStop);
public static <State,Data> boolean transcodeLoop(EConv ec, TranscodeFallback<State,Data> fallbackFunc, State s, Data fallbackData, byte[] inBytes, Ptr inPos, byte[] outBytes, Ptr outPos, int inStop, int outStop, ByteList destination, ResizeFunction resizeFunction) {
Ptr outstopPos = new Ptr(outStop);
Transcoding lastTC = ec.lastTranscoding;
int maxOutput = lastTC != null ? lastTC.transcoder.maxOutput : 1;

Ptr outStart = new Ptr(outPos.p);

// resume:
while (true) {
EConvResult ret = ec.convert(inBytes, inPos, inStop, outBytes, outPos, outStop.p, 0);
EConvResult ret = ec.convert(inBytes, inPos, inStop, outBytes, outPos, outstopPos.p, 0);

if (fallbackFunc != null && ret == EConvResult.UndefinedConversion) {
if (fallbackFunc.call(s, fallbackData, ec)) {
@@ -1331,13 +1349,15 @@ public static <State,Data> boolean transcodeLoop(EConv ec, TranscodeFallback<Sta
}

if (ret == EConvResult.DestinationBufferFull) {
moreOutputBuffer(destination, resizeFunction, maxOutput, outStart, outPos, outStop);
moreOutputBuffer(destination, resizeFunction, maxOutput, outStart, outPos, outstopPos);
outBytes = destination.getUnsafeBytes();
continue;
}

ec.close();

destination.setRealSize(outPos.p);

return true;
}
}
5 changes: 3 additions & 2 deletions spec/ruby/core/file/basename_spec.rb
Original file line number Diff line number Diff line change
@@ -147,8 +147,9 @@
end

it "returns the basename with the same encoding as the original" do
basename = File.basename('/path/file'.encode('Windows-1250'))
basename.encoding.should == Encoding.find('Windows-1250')
basename = File.basename('C:/Users/Scuby Pagrubý'.encode(Encoding::Windows_1250))
basename.should == 'Scuby Pagrubý'.encode(Encoding::Windows_1250)
basename.encoding.should == Encoding::Windows_1250
end

end