Skip to content

Commit

Permalink
Fixes #3642. process_manager: Incompatible subprocess cmd parsing beh…
Browse files Browse the repository at this point in the history
…aviour on 1.7
enebo committed Apr 8, 2016
1 parent a8eef1f commit 8e976a4
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
@@ -1627,18 +1627,26 @@ private static String getShell(Ruby runtime) {
return RbConfigLibrary.jrubyShell();
}

// This is more of a hack than not. If we can detect any ENV logic at front of the
// command we will defer to invoking via shell. We probably should be prarsing off the env
// and invoking this another way but I am leery to change this infrastructure on our
// maintenance branch (jruby-1_7) at this point.
private static boolean firstWordIsENV(String command) {
int space = command.indexOf(' ');

return space != -1 && command.substring(0, space).contains("=");
}

public static boolean shouldUseShell(String command) {
boolean useShell = false;
for (char c : command.toCharArray()) {
if (c != ' ' && !Character.isLetter(c) && "*?{}[]<>()~&|\\$;'`\"\n".indexOf(c) != -1) {
useShell = true;
return true;
}
}
if (Platform.IS_WINDOWS && command.length() >= 1 && command.charAt(0) == '@') {
// JRUBY-5522
useShell = true;
}
return useShell;
if (Platform.IS_WINDOWS && command.length() >= 1 && command.charAt(0) == '@') return true; // JRUBY-5522

return firstWordIsENV(command);
}

static void log(Ruby runtime, String msg) {
2 changes: 1 addition & 1 deletion core/src/main/ruby/jruby/kernel/jruby/process_manager.rb
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ def self.`(command)
config = LaunchConfig.new(JRuby.runtime, [command].to_java(IRubyObject), false)

use_shell = Platform::IS_WINDOWS ? config.should_run_in_shell : false
use_shell |= ShellLauncher.should_use_shell(command)
use_shell ||= ShellLauncher.should_use_shell(command)

if use_shell
config.verify_executable_for_shell

0 comments on commit 8e976a4

Please sign in to comment.