Skip to content

Commit

Permalink
Strip trailing options hash in Open3.popen3 and warn if non-empty.
Browse files Browse the repository at this point in the history
Fixes #2298.
  • Loading branch information
headius committed Dec 10, 2014
1 parent f7082b3 commit 986bd8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions spec/regression/GH-2298_capture3_accepts_trailing_options_spec.rb
@@ -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.