From d957e75721097f36b61fe17364c36dcfdd8eefdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8egh?= Date: Sat, 13 Aug 2016 13:20:09 +0200 Subject: [PATCH] Fix #17956 and add test. The bug was introduced in 103db50aa6c67d8e732e8e2bd7f5743bae17e369 --- base/env.jl | 2 +- test/env.jl | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/base/env.jl b/base/env.jl index fc3fe87e78c70..3c77619400b82 100644 --- a/base/env.jl +++ b/base/env.jl @@ -94,7 +94,7 @@ end function next(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}}) pos = block[1] blk = block[2] - len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos) + len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos) + 1 buf = Array{UInt16}(len) unsafe_copy!(pointer(buf), pos, len) env = transcode(String, buf) diff --git a/test/env.jl b/test/env.jl index 592c378cf65ee..6d57d4217b894 100644 --- a/test/env.jl +++ b/test/env.jl @@ -30,3 +30,36 @@ key = randstring(25) @test !haskey(ENV,key) @test_throws KeyError ENV[key] @test get(ENV,key,"default") == "default" + +# Test for #17956 +@test length(ENV) > 1 +k1, k2 = "__test__", "__test1__" +withenv(k1=>k1, k2=>k2) do + b_k1, b_k2 = false, false + for (k, v) in ENV + if k==k1 + b_k1=true + elseif k==k2 + b_k2=true + end + end + @test b_k1 && b_k2 + io = IOBuffer() + show(io, ENV) + s = takebuf_string(io) + @test contains(s, k1) + @test contains(s, k2) + + @test pop!(ENV, k1) == k1 + @test !haskey(ENV, k1) + ENV[k1] = k1 + @test pop!(ENV, k1) == k1 + @test pop!(ENV, k1, "not_there") == "not_there" + + ENV[k1] = k1 + @test delete!(ENV, k1) == ENV + @test !haskey(ENV, k1) +end + +# Test for #10853 +@test withenv(Dict{Any,Any}()...) do; true; end