Skip to content

Commit

Permalink
JRUBY-4834: Kernel.exec doesn't use modified ENV["PATH"] to locate co…
Browse files Browse the repository at this point in the history
…mmands on Windows

One regression test added as well.
  • Loading branch information
vvs committed Jun 12, 2010
1 parent 83f1a81 commit a9ad2ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/org/jruby/util/ShellLauncher.java
Expand Up @@ -28,10 +28,12 @@


package org.jruby.util; package org.jruby.util;


import static java.lang.System.out;

import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.BufferedInputStream;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
Expand All @@ -40,15 +42,14 @@
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import static java.lang.System.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern;


import org.jruby.Main; import org.jruby.Main;
import org.jruby.Ruby; import org.jruby.Ruby;
Expand Down Expand Up @@ -330,7 +331,11 @@ private static File findPathFile(Ruby runtime, String fname, String[] path, bool
} }


private static File findPathExecutable(Ruby runtime, String fname) { 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; String[] pathNodes = null;
if (path == null) { if (path == null) {
pathNodes = DEFAULT_PATH; // ASSUME: not modified by callee pathNodes = DEFAULT_PATH; // ASSUME: not modified by callee
Expand Down
15 changes: 15 additions & 0 deletions test/test_kernel.rb
Expand Up @@ -502,6 +502,21 @@ def test_exec_non_existing_with_args
} }
end 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 # JRUBY-4127
def test_backquote_with_quotes def test_backquote_with_quotes
if (WINDOWS) if (WINDOWS)
Expand Down

0 comments on commit a9ad2ae

Please sign in to comment.