Permalink
Browse files

JRUBY-4834: Kernel.exec doesn't use modified ENV["PATH"] to locate co…

…mmands on Windows

One regression test added as well.
  • Loading branch information...
1 parent 83f1a81 commit a9ad2aebb70b6758fd04131955451bbfbdfe5976 @vvs vvs committed Jun 12, 2010
Showing with 24 additions and 4 deletions.
  1. +9 −4 src/org/jruby/util/ShellLauncher.java
  2. +15 −0 test/test_kernel.rb
@@ -28,10 +28,12 @@
package org.jruby.util;
+import static java.lang.System.out;
+
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.BufferedInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -40,15 +42,14 @@
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
-import static java.lang.System.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.regex.Pattern;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.jruby.Main;
import org.jruby.Ruby;
@@ -330,7 +331,11 @@ private static File findPathFile(Ruby runtime, String fname, String[] path, bool
}
private static File findPathExecutable(Ruby runtime, String fname) {
- String path = System.getenv(PATH_ENV);
+ RubyHash envHash = (RubyHash) runtime.getObject().fastGetConstant("ENV");
+ String path = envHash.op_aref(
+ runtime.getCurrentContext(),
+ runtime.newString(PATH_ENV)).asJavaString();
+
String[] pathNodes = null;
if (path == null) {
pathNodes = DEFAULT_PATH; // ASSUME: not modified by callee
View
@@ -502,6 +502,21 @@ def test_exec_non_existing_with_args
}
end
+ # JRUBY-4834
+ def test_backquote_with_changed_path
+ orig_env = ENV['PATH']
+
+ # Append a directory where testapp resides to the PATH
+ paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
+ paths.unshift TESTAPP_DIR
+ ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR)
+
+ res = `testapp`.chomp
+ assert_equal("NO_ARGS", res)
+ ensure
+ ENV['PATH'] = orig_env
+ end
+
# JRUBY-4127
def test_backquote_with_quotes
if (WINDOWS)

0 comments on commit a9ad2ae

Please sign in to comment.