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: 5166c0dba377
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0dfd50156ffe
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 18, 2014

  1. Copy the full SHA
    2515fc0 View commit details
  2. Copy the full SHA
    681fe89 View commit details
  3. Copy the full SHA
    0dfd501 View commit details
33 changes: 21 additions & 12 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -767,12 +767,12 @@ public static IRubyObject extname(ThreadContext context, IRubyObject recv, IRuby
*/
@JRubyMethod(required = 1, optional = 1, meta = true, compat = CompatVersion.RUBY1_8)
public static IRubyObject expand_path(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, true);
return expandPathInternal(context, recv, args, true, false);
}

@JRubyMethod(name = "expand_path", required = 1, optional = 1, meta = true, compat = CompatVersion.RUBY1_9)
public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
RubyString path = (RubyString) expandPathInternal(context, recv, args, true);
RubyString path = (RubyString) expandPathInternal(context, recv, args, true, false);
path.force_encoding(context, context.runtime.getEncodingService().getDefaultExternal());

return path;
@@ -800,25 +800,21 @@ public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv,
*/
@JRubyMethod(required = 1, optional = 1, meta = true, compat = RUBY1_9)
public static IRubyObject absolute_path(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, false);
return expandPathInternal(context, recv, args, false, false);
}

@JRubyMethod(name = {"realdirpath"}, required = 1, optional = 1, meta = true, compat = RUBY1_9)
public static IRubyObject realdirpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, false);
return expandPathInternal(context, recv, args, false, false);
}

@JRubyMethod(name = {"realpath"}, required = 1, optional = 1, meta = true, compat = RUBY1_9)
public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
IRubyObject file = expandPathInternal(context, recv, args, false);
IRubyObject file = expandPathInternal(context, recv, args, false, true);
if (!RubyFileTest.exist_p(recv, file).isTrue()) {
throw context.runtime.newErrnoENOENTError(file.toString());
}
try {
return context.runtime.newString(new File(file.toString()).getCanonicalPath());
} catch (IOException ioex) {
throw context.runtime.newErrnoENOENTError(file.toString());
}
return file;
}

/**
@@ -1580,7 +1576,7 @@ private static boolean isWindowsDriveLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser) {
private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser, boolean canonicalize) {
Ruby runtime = context.runtime;

String relativePath = get_path(context, args[0]).getUnicodeValue();
@@ -1611,6 +1607,9 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
relativePath = uriParts[1];
}

// Now that we're not treating it as a URI, we need to honor the canonicalize flag.
// Do not insert early returns below.

// If there's a second argument, it's the path to which the first
// argument is relative.
if (args.length == 2 && !args[1].isNil()) {
@@ -1700,7 +1699,17 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
path = JRubyFile.create(cwd, relativePath);
}

return runtime.newString(padSlashes + canonicalize(path.getAbsolutePath()));
String realPath = padSlashes + canonicalize(path.getAbsolutePath());

if (canonicalize) {
try {
realPath = new File(realPath).getCanonicalPath();
} catch (IOException ioe) {
// Earlier canonicalization will have to do.
}
}

return runtime.newString(realPath);
}

public static String[] splitURI(String path) {
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -1865,7 +1865,8 @@ private static int initGlobalJavaVersion() {
} else if (specDecimal.compareTo(BIGDECIMAL_1_5) >= 0) {
return Opcodes.V1_5;
} else {
throw new RuntimeException("unsupported Java version: " + specVersion);
System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.5");
return Opcodes.V1_5;
}
}

Original file line number Diff line number Diff line change
@@ -520,11 +520,21 @@ public void endScript(boolean generateLoad, boolean generateMain) {
SkinnyMethodAdapter method = new SkinnyMethodAdapter(getClassVisitor(), ACC_PUBLIC | ACC_STATIC, "main", sig(Void.TYPE, params(String[].class)), null, null);
method.start();

// init script filename to simple class name in case we don't assign it (null ClassLoader)
method.ldc(getClassname().replaceAll("\\\\.", "/"));
method.astore(1);

// new instance to invoke run against
method.newobj(getClassname());
method.dup();
method.invokespecial(getClassname(), "<init>", sig(Void.TYPE));

// guard against null classloader
method.ldc(Type.getType("L" + getClassname() + ";"));
method.invokevirtual(p(Class.class), "getClassLoader", sig(ClassLoader.class));
Label skip = new Label();
method.ifnull(skip);

// set filename for the loaded script class (JRUBY-4825)
method.dup();
method.ldc(Type.getType("L" + getClassname() + ";"));
@@ -536,6 +546,9 @@ public void endScript(boolean generateLoad, boolean generateMain) {
method.aload(1);
method.invokevirtual(p(AbstractScript.class), "setFilename", sig(void.class, String.class));

// ifnull ClassLoader
method.label(skip);

// instance config for the script run
method.newobj(p(RubyInstanceConfig.class));
method.dup();
5 changes: 5 additions & 0 deletions test/test_file.rb
Original file line number Diff line number Diff line change
@@ -1213,4 +1213,9 @@ def test_file_path_is_tainted
io.close
File.unlink(filename)
end

# jruby/jruby#2331
def test_classpath_realpath
assert_equal("classpath:/java/lang/String.class", File.realpath("classpath:/java/lang/String.class"))
end
end