Skip to content

Commit edce1da

Browse files
committed
Dedup checkExecEnv logic.
1 parent 4c52c92 commit edce1da

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,29 +4476,7 @@ private static void checkValidOptions(IRubyObject options, Set<String> valid) {
44764476

44774477
// MRI: check_exec_env, w/ check_exec_env_i body in-line
44784478
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
4479-
Ruby runtime = context.runtime;
4480-
RubyArray env = runtime.newArray();
4481-
for (Map.Entry<IRubyObject, IRubyObject> entry : (Set<Map.Entry<IRubyObject, IRubyObject>>)hash.directEntrySet()) {
4482-
IRubyObject key = entry.getKey();
4483-
IRubyObject val = entry.getValue();
4484-
ByteList k;
4485-
4486-
k = StringSupport.checkEmbeddedNulls(runtime, key).getByteList();
4487-
if (k.indexOf('=') != -1)
4488-
throw runtime.newArgumentError("environment name contains a equal : " + k);
4489-
4490-
if (!val.isNil())
4491-
StringSupport.checkEmbeddedNulls(runtime, val);
4492-
4493-
if (Platform.IS_WINDOWS) {
4494-
key = ((RubyString)key).export(context);
4495-
}
4496-
if (!val.isNil()) val = ((RubyString)val).export(context);
4497-
4498-
env.push(runtime.newArray(key, val));
4499-
}
4500-
4501-
return env;
4479+
return PopenExecutor.checkExecEnv(context, hash);
45024480
}
45034481

45044482
/**

core/src/main/java/org/jruby/util/io/PopenExecutor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.jruby.runtime.ThreadContext;
2424
import org.jruby.runtime.builtin.IRubyObject;
2525
import org.jruby.util.ByteList;
26-
import org.jruby.util.SafePropertyAccessor;
2726
import org.jruby.util.ShellLauncher;
2827
import org.jruby.util.StringSupport;
2928
import org.jruby.util.TypeConverter;
@@ -314,10 +313,11 @@ public static IRubyObject popen(ThreadContext context, IRubyObject[] argv, RubyC
314313
}
315314

316315
static void execargSetenv(ThreadContext context, Ruby runtime, ExecArg eargp, IRubyObject env) {
317-
eargp.env_modification = !env.isNil() ? checkExecEnv(context, runtime, (RubyHash)env) : null;
316+
eargp.env_modification = !env.isNil() ? checkExecEnv(context, (RubyHash)env) : null;
318317
}
319318

320-
static RubyArray checkExecEnv(ThreadContext context, Ruby runtime, RubyHash hash) {
319+
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
320+
Ruby runtime = context.runtime;
321321
RubyArray env;
322322

323323
env = runtime.newArray();
@@ -1769,7 +1769,7 @@ private static void execFillarg(ThreadContext context, RubyString prog, IRubyObj
17691769
}
17701770

17711771
if (!env.isNil()) {
1772-
eargp.env_modification = RubyIO.checkExecEnv(context, (RubyHash)env);
1772+
eargp.env_modification = checkExecEnv(context, (RubyHash) env);
17731773
}
17741774

17751775
prog = prog.export(context);

0 commit comments

Comments
 (0)