fix: force base-10 in version_gte to prevent octal interpretation

Use 10#$var arithmetic prefix to avoid bash interpreting leading
zeros as octal (e.g., 08 or 09 would cause "value too great for
base" errors). 2 new tests (64 total).

Closes: #9

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Flo
2026-03-30 23:45:04 +02:00
parent d204ae5a9a
commit 902d1abac0
2 changed files with 20 additions and 7 deletions

View File

@@ -209,14 +209,15 @@ version_gte() {
# shellcheck disable=SC2086 # shellcheck disable=SC2086
set -- $1 $2 set -- $1 $2
IFS="$IFS_SAVE" IFS="$IFS_SAVE"
local a1="${1:-0}" a2="${2:-0}" a3="${3:-0}" # Force base-10 interpretation to avoid octal issues with leading zeros
local b1="${4:-0}" b2="${5:-0}" b3="${6:-0}" local a1=$((10#${1:-0})) a2=$((10#${2:-0})) a3=$((10#${3:-0}))
local b1=$((10#${4:-0})) b2=$((10#${5:-0})) b3=$((10#${6:-0}))
if [ "$a1" -gt "$b1" ] 2>/dev/null; then return 0; fi if [ "$a1" -gt "$b1" ]; then return 0; fi
if [ "$a1" -lt "$b1" ] 2>/dev/null; then return 1; fi if [ "$a1" -lt "$b1" ]; then return 1; fi
if [ "$a2" -gt "$b2" ] 2>/dev/null; then return 0; fi if [ "$a2" -gt "$b2" ]; then return 0; fi
if [ "$a2" -lt "$b2" ] 2>/dev/null; then return 1; fi if [ "$a2" -lt "$b2" ]; then return 1; fi
if [ "$a3" -ge "$b3" ] 2>/dev/null; then return 0; fi if [ "$a3" -ge "$b3" ]; then return 0; fi
return 1 return 1
} }

View File

@@ -108,6 +108,18 @@ source_functions() {
assert_failure assert_failure
} }
@test "version_gte: handles leading zeros without octal error" {
source_functions
run version_gte "2.08.0" "2.07.0"
assert_success
}
@test "version_gte: leading zero comparison works correctly" {
source_functions
run version_gte "2.09.1" "2.09.0"
assert_success
}
# =========================================================================== # ===========================================================================
# Version extraction (grep-based, not sed) # Version extraction (grep-based, not sed)
# =========================================================================== # ===========================================================================