diff --git a/bin/download b/bin/download index 46e7059..6c54651 100755 --- a/bin/download +++ b/bin/download @@ -32,6 +32,9 @@ download_golang() { local platform="" local arch="" + # Validate version format before attempting download + validate_version "$version" + platform=$(get_platform) arch=$(get_arch) download_url="https://dl.google.com/go/go${version}.${platform}-${arch}.tar.gz" diff --git a/lib/helpers.sh b/lib/helpers.sh index 64e37bf..c3cd04f 100644 --- a/lib/helpers.sh +++ b/lib/helpers.sh @@ -39,6 +39,16 @@ get_arch() { printf "%s" "$arch" } +validate_version() { + local version="$1" + + # Check if version matches the pattern major.minor.patch + # This allows for versions like 1.21.0, 1.22.1, etc. + if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + fail "Invalid version format: '$version'. Go versions must be in the format 'major.minor.patch' (e.g., '1.25.0')." + fi +} + msg() { echo -e "\033[32m$1\033[39m" >&2 }