Skip to content

Commit

Permalink
Fixes JuliaLang#18141, eliminating null in value when iterating over …
Browse files Browse the repository at this point in the history
…`ENV`. (JuliaLang#18144)

* Eliminate trailing null from iterator over `ENV`.

Fixes JuliaLang#18141.

* Add failing test for JuliaLang#18141.
  • Loading branch information
twadleigh authored and tkelman committed Aug 20, 2016
1 parent 6f2c1c4 commit 03e7c79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ if is_windows()
function next(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
pos = block[1]
blk = block[2]
len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos) + 1
len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos)
buf = Array{UInt16}(len)
unsafe_copy!(pointer(buf), pos, len)
env = transcode(String, buf)
m = match(r"^(=?[^=]+)=(.*)$"s, env)
if m === nothing
error("malformed environment entry: $env")
end
return (Pair{String,String}(m.captures[1], m.captures[2]), (pos+len*2, blk))
return (Pair{String,String}(m.captures[1], m.captures[2]), (pos+(len+1)*2, blk))
end
else # !windows
start(::EnvHash) = 0
Expand Down
7 changes: 7 additions & 0 deletions test/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ end

# Test for #10853
@test withenv(Dict{Any,Any}()...) do; true; end

# Test for #18141
for (k, v) in ENV
if length(v) > 0
@test v[end] != '\0'
end
end

0 comments on commit 03e7c79

Please sign in to comment.