Skip to content

Commit

Permalink
Convert environment variable values to strings when posix_spawn enabled
Browse files Browse the repository at this point in the history
Issue #128 pointed out that there was inconsistency between how
environment variables were treated on *nix systems by ChildProcess'
fork/exec implementation versus POSIX spawn.

Since the behavior of the more common case of fork/exec is to convert
the values to strings, we'll do the same for POSIX spawn. However, a
better long term solution would likely be to raise an error on
non-string values.
  • Loading branch information
sds committed Jan 12, 2019
1 parent 576c249 commit 5c57733
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/childprocess/unix/posix_spawn_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ def initialize(env)
@ptrs = env.map do |key, val|
next if val.nil?

if key =~ /=|\0/ || val.include?("\0")
raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
if key =~ /=|\0/ || val.to_s.include?("\0")
raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.to_s.inspect}"
end

FFI::MemoryPointer.from_string("#{key}=#{val}")
FFI::MemoryPointer.from_string("#{key}=#{val.to_s}")
end.compact

@ptrs << FFI::Pointer.new(0)
Expand Down

0 comments on commit 5c57733

Please sign in to comment.