From b47d0b0b6894eb3bea31dff8b31254a0f4123a16 Mon Sep 17 00:00:00 2001 From: "Timothy G. Flynn" Date: Mon, 2 Sep 2019 13:49:17 -0400 Subject: [PATCH 1/6] Fix behavior of Sys.which when passed an empty String argument --- base/sysinfo.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 1cbe3a994bcd8..22f41bace8e59 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -459,6 +459,9 @@ for executable permissions only (with `.exe` and `.com` extensions added on Windows platforms); no searching of `PATH` is performed. """ function which(program_name::String) + if isempty(program_name) + return nothing + end # Build a list of program names that we're going to try program_names = String[] base_pname = basename(program_name) From 76bf01f6565dbf24ee12d43874199a1872022cad Mon Sep 17 00:00:00 2001 From: "Timothy G. Flynn" Date: Tue, 3 Sep 2019 16:17:35 -0400 Subject: [PATCH 2/6] Added test to check for fixed Sys.which behavior with empty string input --- test/sysinfo.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/sysinfo.jl b/test/sysinfo.jl index a34adf572abe4..3a9bb6754a25f 100644 --- a/test/sysinfo.jl +++ b/test/sysinfo.jl @@ -6,3 +6,6 @@ sprint(Base.Sys.cpu_summary) @test Base.Sys.uptime() > 0 Base.Sys.loadavg() + +# Check that which behaves correctly when passed an empty string +@test isnothing(Base.Sys.which("")) From 2c8ba62c0b89e817bc73afe58da9efec0ea52029 Mon Sep 17 00:00:00 2001 From: "Timothy G. Flynn" Date: Tue, 3 Sep 2019 17:04:29 -0400 Subject: [PATCH 3/6] Added test to check that Sys.which returns nothing when passed a blank string --- test/sysinfo.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/sysinfo.jl b/test/sysinfo.jl index 3a9bb6754a25f..343942bdc03b0 100644 --- a/test/sysinfo.jl +++ b/test/sysinfo.jl @@ -9,3 +9,6 @@ Base.Sys.loadavg() # Check that which behaves correctly when passed an empty string @test isnothing(Base.Sys.which("")) + +# Check that which behaves correctly when passed a blank string +@test isnothing(Base.Sys.which(" ")) From 31e7d7aab3fc3f6afbf5ad77834f1b0c4b6158b3 Mon Sep 17 00:00:00 2001 From: "Timothy G. Flynn" Date: Tue, 3 Sep 2019 17:14:18 -0400 Subject: [PATCH 4/6] Ensure that Sys.which returns a regular file and never a directory --- base/sysinfo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 22f41bace8e59..df71537ad05f5 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -504,7 +504,7 @@ function which(program_name::String) for pname in program_names program_path = joinpath(path_dir, pname) # If we find something that matches our name and we can execute - if isexecutable(program_path) + if isfile(program_path) && isexecutable(program_path) return realpath(program_path) end end From 0198ad917e7d8612cd5ae3356fb9115febfe2eac Mon Sep 17 00:00:00 2001 From: "Timothy G. Flynn" Date: Tue, 3 Sep 2019 18:26:19 -0400 Subject: [PATCH 5/6] Moved new Sys.which tests into test/spawn.jl alongside the existing ones --- test/spawn.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/spawn.jl b/test/spawn.jl index 535aec6b3f0c3..d62179724097f 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -556,6 +556,10 @@ withenv("PATH" => "$(Sys.BINDIR)$(psep)$(ENV["PATH"])") do @test Sys.which(julia_exe) == realpath(julia_exe) end +# Check that which behaves correctly when passed an empty string +@test isnothing(Base.Sys.which("")) + + mktempdir() do dir withenv("PATH" => "$(dir)$(psep)$(ENV["PATH"])") do # Test that files lacking executable permissions fail Sys.which @@ -572,8 +576,15 @@ mktempdir() do dir @test Sys.which(foo_path) === nothing end + end + + # Ensure these tests are done only with a PATH of known contents + withenv("PATH" => "$(dir)") do # Test that completely missing files also return nothing @test Sys.which("this_is_not_a_command") === nothing + + # Check that which behaves correctly when passed a blank string + @test isnothing(Base.Sys.which(" ")) end end From a264f017549ae1214656415498fd92b2f4b3061f Mon Sep 17 00:00:00 2001 From: "Timothy G. Flynn" Date: Tue, 3 Sep 2019 22:11:38 -0400 Subject: [PATCH 6/6] Remove new which tests from test/sysinfo.jl (they've moved to test/spawn.jl) --- test/sysinfo.jl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/sysinfo.jl b/test/sysinfo.jl index 343942bdc03b0..a34adf572abe4 100644 --- a/test/sysinfo.jl +++ b/test/sysinfo.jl @@ -6,9 +6,3 @@ sprint(Base.Sys.cpu_summary) @test Base.Sys.uptime() > 0 Base.Sys.loadavg() - -# Check that which behaves correctly when passed an empty string -@test isnothing(Base.Sys.which("")) - -# Check that which behaves correctly when passed a blank string -@test isnothing(Base.Sys.which(" "))