fix: crashes on alias arg substitution

- ignore 0 index in arg substitution
- fix out of bounds check
pull/258/head
sammyette 2023-07-11 13:45:18 -04:00
parent 9e80b4bf50
commit d844b8dc22
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 3 additions and 3 deletions

View File

@ -54,12 +54,12 @@ func (a *aliasModule) Resolve(cmdstr string) string {
for a.aliases[args[0]] != "" { for a.aliases[args[0]] != "" {
alias := a.aliases[args[0]] alias := a.aliases[args[0]]
alias = arg.ReplaceAllStringFunc(alias, func(a string) string { alias = arg.ReplaceAllStringFunc(alias, func(a string) string {
if strings.HasPrefix(a, "\\") { idx, _ := strconv.Atoi(a[1:])
if strings.HasPrefix(a, "\\") || idx == 0 {
return strings.TrimPrefix(a, "\\") return strings.TrimPrefix(a, "\\")
} }
idx, _ := strconv.Atoi(a[1:]) if idx + 1 > len(args) {
if idx > len(args) {
return a return a
} }
val := args[idx] val := args[idx]