From d803989131e58c56aa5cf159fdf12ae20fe04197 Mon Sep 17 00:00:00 2001 From: Joshua Rogers Date: Fri, 12 Jan 2024 01:17:56 +0700 Subject: [PATCH] An empty filename or directory is not allowed. --- Snake.nocomments.sh | 2 ++ Snake.sh | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Snake.nocomments.sh b/Snake.nocomments.sh index 8348943..1087ae8 100644 --- a/Snake.nocomments.sh +++ b/Snake.nocomments.sh @@ -1063,6 +1063,7 @@ done is_file() { local filename filename="$1" +[[ -z "$filename" ]] && return 1 [[ -v 'files["$filename"]' || ${#files["$filename"]} -gt 0 ]] && return 0 [[ -v 'not_files["$filename"]' || ${#not_files["$filename"]} -gt 0 ]] && return 1 ${s} test -s "$filename" && ${s} test -r "$filename" && ${s} test -f "$filename" && files["$filename"]=1 && return 0 @@ -1072,6 +1073,7 @@ return 1 is_dir() { local dir_name dir_name="$1" +[[ -z "$dir_name" ]] && return 1 [[ -v 'folders["$dir_name"]' || ${#folders["$dir_name"]} -gt 0 ]] && return 0 [[ -v 'not_folders["$dir_name"]' || ${#not_folders["$dir_name"]} -gt 0 ]] && return 1 ${s} test -d "$dir_name" && ${s} test -r "$dir_name" && folders["$dir_name"]=1 && return 0 diff --git a/Snake.sh b/Snake.sh index 2d97c61..b25eaf2 100755 --- a/Snake.sh +++ b/Snake.sh @@ -1785,6 +1785,8 @@ is_file() { filename="$1" + [[ -z "$filename" ]] && return 1 + [[ -v 'files["$filename"]' || ${#files["$filename"]} -gt 0 ]] && return 0 [[ -v 'not_files["$filename"]' || ${#not_files["$filename"]} -gt 0 ]] && return 1 @@ -1800,6 +1802,8 @@ is_dir() { dir_name="$1" + [[ -z "$dir_name" ]] && return 1 + [[ -v 'folders["$dir_name"]' || ${#folders["$dir_name"]} -gt 0 ]] && return 0 [[ -v 'not_folders["$dir_name"]' || ${#not_folders["$dir_name"]} -gt 0 ]] && return 1