fixes #25738; std/parseopt: - causes IndexDefect (#25739)

(cherry picked from commit cf3c28c223)
This commit is contained in:
lit
2026-04-12 18:32:25 +08:00
committed by narimiran
parent 68bcee04a1
commit 73102bddab
2 changed files with 12 additions and 1 deletions

View File

@@ -588,7 +588,9 @@ proc handleShortOption(p: var OptParser; cmd: string) =
template next(): untyped = p.cmds[p.idx + 1]
let canTakeVal = card(p.shortNoVal) > 0 and p.key[0] notin p.shortNoVal
let canTakeVal = card(p.shortNoVal) > 0 and
p.key.len > 0 and p.key[0] notin p.shortNoVal
if i < cmd.len and cmd[i] in p.separators:
# separator case
if prShortAllowSep in p.rules:

View File

@@ -31,6 +31,9 @@ cmdShortOption key: v value: ''
cmdArgument key: ABC value: ''
cmdShortOption key: j value: '4'
cmdArgument key: ok value: ''
parseopt stdin
cmdShortOption key: j value: '4'
cmdShortOption key: value: ''
'''
joinable: false
"""
@@ -154,3 +157,9 @@ arg 6 ai.len:4 :{a7'b}"""
var n = parseopt.initOptParser("-j4 ok", shortnoVal = {'n'}, longnoVal = @["novalue"])
for kind, key, val in parseopt.getopt(n):
echo kind," key: ", key, " value: '", val, "'"
block: # fix #25738
echo "parseopt stdin"
var p = parseopt.initOptParser("-j4 -", shortNoVal = {'n'})
for kind, key, val in parseopt.getopt(p):
echo kind," key: ", key, " value: '", val, "'"