Skip to content

Commit c448609

Browse files
committed
Fix non-native IO.popen env + kwargs handling
When both an env hash and a keyword arguments hash were provided here, the env hash logic would decrement argc resulting in the keyword arguments hash detection accessing the wrong argument. The fix here aligns this logic with the newer PopenExecutor and ensures the keyword arguments hash is handled first. The argument processing logic for these two popen implementations should be unified, but this simple fix gets popen working better right now. Fixes jruby#9295
1 parent 831e875 commit c448609

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

core/src/main/java/org/jruby/RubyIO.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,13 +4518,15 @@ public static IRubyObject popen(ThreadContext context, IRubyObject recv, IRubyOb
45184518

45194519
int firstArg = 0;
45204520

4521-
if (argc > 0 && !TypeConverter.checkHashType(runtime, args[0]).isNil()) {
4522-
firstArg++;
4521+
// process trailing keyword arguments hash
4522+
if (argc > 0 && !(tmp = TypeConverter.checkHashType(runtime, args[argc - 1])).isNil()) {
4523+
options = (RubyHash)tmp;
45234524
argc--;
45244525
}
45254526

4526-
if (argc > 0 && !(tmp = TypeConverter.checkHashType(runtime, args[argc - 1])).isNil()) {
4527-
options = (RubyHash)tmp;
4527+
// process leading env hash
4528+
if (argc > 0 && !TypeConverter.checkHashType(runtime, args[0]).isNil()) {
4529+
firstArg++;
45284530
argc--;
45294531
}
45304532

0 commit comments

Comments
 (0)