Skip to content
Permalink
Browse files
Strip trailing options hash in Open3.popen3 and warn if non-empty.
Fixes #2298.
  • Loading branch information
headius committed Dec 10, 2014
1 parent f7082b3 commit 986bd8d514352edba2267d23e40a45454b76dd3f
Showing with 18 additions and 0 deletions.
  1. +8 −0 core/src/main/java/org/jruby/util/ShellLauncher.java
  2. +10 −0 spec/regression/GH-2298_capture3_accepts_trailing_options_spec.rb
@@ -739,6 +739,14 @@ private static Process popenShared(Ruby runtime, IRubyObject[] strings, Map env,
env = (Map)envHash;
}

// Peel off options hash and warn that we don't support them
if (strings.length > 1 && !(envHash = TypeConverter.checkHashType(runtime, strings[strings.length - 1])).isNil()) {
if (!((RubyHash)envHash).isEmpty()) {
runtime.getWarnings().warn("popen3 does not support spawn options in JRuby 1.7");
}
strings = Arrays.copyOfRange(strings, 0, strings.length - 1);
}

String[] args = parseCommandLine(runtime.getCurrentContext(), runtime, strings);
boolean useShell = false;
if (addShell) for (String arg : args) useShell |= shouldUseShell(arg);
@@ -0,0 +1,10 @@
require 'open3'

describe "Open3.popen3" do
it "accepts and ignores empty trailing options hash" do
# capture3 is an easy way to test popen3 options behavior
result = Open3.capture3('echo')

expect(result[0]).to eq "\n"
end
end

0 comments on commit 986bd8d

Please sign in to comment.