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: a2cdff8d52ef
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 04244133b346
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 23, 2017

  1. Copy the full SHA
    e2d8cdf View commit details
  2. Fixes ruby/spec failure for File#join where we would process windows …

    …delimited path on non-windows platforms
    enebo committed Feb 23, 2017
    Copy the full SHA
    0424413 View commit details
Showing with 29 additions and 15 deletions.
  1. +29 −11 core/src/main/java/org/jruby/RubyFile.java
  2. +0 −4 spec/tags/ruby/core/file/join_tags.txt
40 changes: 29 additions & 11 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -2046,9 +2046,16 @@ private static boolean joinImpl(final StringBuilder buffer, final String separat
element = path.getUnicodeValue();
}

chomp(buffer);
if (i > 0 && !startsWith(element, separator)) {
buffer.append(separator);
int trailingDelimiterIndex = chomp(buffer);
boolean leadingDelimiter = startsWith(element, separator);
boolean trailingDelimiter = trailingDelimiterIndex != -1;
if (i > 0) {
if (leadingDelimiter) {
// both present delete trailing delimiter(s)
if (trailingDelimiter) buffer.delete(trailingDelimiterIndex, buffer.length());
} else if (!trailingDelimiter) { // no edge delimiters are present add supplied separator
buffer.append(separator);
}
}
buffer.append(element);
}
@@ -2077,17 +2084,28 @@ private static StringBuilder joinImplInspecting(final String separator,
}
}

private static void chomp(final StringBuilder buffer) {
int lastIndex = buffer.length() - 1;
// FIXME: MRI and JRuby are both broken here since it does not actually look up
// File::{SEPARATOR,ALT_SEPARATOR} but merely hardcodes depending on whether we are on Windows.
private static boolean isDirSeparator(char c) {
return c == '/' || Platform.IS_WINDOWS && c == '\\';
}

// Return the last index before where there is a delimeter. Otherwise -1.
// If there are non-consecutive delimeters at the end we will return the
// first non-delimiter character.
private static int chomp(final StringBuilder buffer) {
boolean found = false;

while ( lastIndex >= 0 ) {
char c = buffer.charAt(lastIndex);
if ( c == '/' || c == '\\' ) {
buffer.setLength(lastIndex--);
continue;
for (int lastIndex = buffer.length() - 1; lastIndex >= 0; lastIndex--) {
if (!isDirSeparator(buffer.charAt(lastIndex))) {
if (found) return lastIndex + 1;
break;
}
break;

found = true;
}

return found ? 0 : -1;
}

// String.startsWith for a CharSequence
4 changes: 0 additions & 4 deletions spec/tags/ruby/core/file/join_tags.txt

This file was deleted.