return empty completion lines on unsupported `COMP_POINT` (#76)

When `COMP_POINT` is invalid or out of range, return an empty list of
completions instead of raising `ValueError`. This matches behaviour for
`comp_point < 0 or comp_point > len(comp_line)` cases.
This commit is contained in:
Etan Kissling 2023-07-07 13:03:23 +02:00 committed by GitHub
parent d0d6fb45b2
commit c67257660b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -31,7 +31,7 @@ proc parseQuoted(l: var ShellLexer, pos: int, isSingle: bool, output: var string
of '\\': of '\\':
# Consume the backslash and the following character # Consume the backslash and the following character
inc(pos) inc(pos)
if (isSingle and l.buf[pos] in {'\''}) or if (isSingle and l.buf[pos] in {'\''}) or
(not isSingle and l.buf[pos] in {'$', '`', '\\', '"'}): (not isSingle and l.buf[pos] in {'$', '`', '\\', '"'}):
# Escape the character # Escape the character
output.add(l.buf[pos]) output.add(l.buf[pos])
@ -120,7 +120,11 @@ proc getTok(l: var ShellLexer): Option[string] =
proc splitCompletionLine*(): seq[string] = proc splitCompletionLine*(): seq[string] =
let comp_line = os.getEnv("COMP_LINE") let comp_line = os.getEnv("COMP_LINE")
var comp_point = parseInt(os.getEnv("COMP_POINT", "0")) var comp_point =
try:
parseInt(os.getEnv("COMP_POINT", "0"))
except ValueError:
return @[]
if comp_point == len(comp_line): if comp_point == len(comp_line):
comp_point -= 1 comp_point -= 1