summaryrefslogtreecommitdiffstats
path: root/t/t0040-parse-options.sh
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-11-09 15:16:27 +0100
committerTaylor Blau <me@ttaylorr.com>2022-11-10 03:30:39 +0100
commit7595c0ece1d45ca540f26cecf485285f5ce8186f (patch)
treee91b323a5b5e2f12b7ff97ed8b71782897c9dde4 /t/t0040-parse-options.sh
parentgit_parse_unsigned: reject negative values (diff)
downloadgit-7595c0ece1d45ca540f26cecf485285f5ce8186f.tar.xz
git-7595c0ece1d45ca540f26cecf485285f5ce8186f.zip
config: require at least one digit when parsing numbers
If the input to strtoimax() or strtoumax() does not contain any digits then they return zero and set `end` to point to the start of the input string. git_parse_[un]signed() do not check `end` and so fail to return an error and instead return a value of zero if the input string is a valid units factor without any digits (e.g "k"). Tests are added to check that 'git config --int' and OPT_MAGNITUDE() reject a units specifier without a leading digit. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 't/t0040-parse-options.sh')
-rwxr-xr-xt/t0040-parse-options.sh7
1 files changed, 7 insertions, 0 deletions
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 64d2327b74..7d7ecfd571 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -714,4 +714,11 @@ test_expect_success 'negative magnitude' '
grep "non-negative integer" err &&
test_must_be_empty out
'
+
+test_expect_success 'magnitude with units but no numbers' '
+ test_must_fail test-tool parse-options --magnitude m >out 2>err &&
+ grep "non-negative integer" err &&
+ test_must_be_empty out
+'
+
test_done