From def53fd73f01663e6d8a42663e01d7f9f13e5356 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 12 Mar 2021 17:05:26 +0200 Subject: [PATCH] os: prevent os.exists_in_system_path() from panicing --- vlib/os/os.v | 3 +++ vlib/os/os_test.v | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/vlib/os/os.v b/vlib/os/os.v index ed5009c4f8..3399c3ecff 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -375,6 +375,9 @@ fn executable_fallback() string { // find_exe_path walks the environment PATH, just like most shell do, it returns // the absolute path of the executable if found pub fn find_abs_path_of_executable(exepath string) ?string { + if exepath == '' { + return error('expected non empty `exepath`') + } if is_abs_path(exepath) { return real_path(exepath) } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index cface1ebf7..b055263f74 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -543,3 +543,12 @@ fn test_posix_set_bit() { rm(fpath) or {} } } + +fn test_exists_in_system_path() { + assert os.exists_in_system_path('') == false + $if windows { + assert os.exists_in_system_path('cmd') == true + return + } + assert os.exists_in_system_path('ls') == true +}