diff options
author | Mikael Magnusson <mikachu@gmail.com> | 2020-05-09 07:43:10 +0200 |
---|---|---|
committer | Mikael Magnusson <mikachu@gmail.com> | 2020-05-12 10:13:02 +0200 |
commit | 817d461932eabff7c1bc950411715ef8ea10c593 (patch) | |
tree | ee956ea994dc4ec1ae2b876064ae459de218a1af | |
parent | 494f6bcb3ca00626ac66348c572a9a69d8b0af37 (diff) | |
download | zsh-817d461932eabff7c1bc950411715ef8ea10c593.tar.gz zsh-817d461932eabff7c1bc950411715ef8ea10c593.tar.xz zsh-817d461932eabff7c1bc950411715ef8ea10c593.zip |
Support ${name:offset:length} with an empty offset
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/subst.c | 20 |
2 files changed, 20 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog index 2ec2e1653..88c46245e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-12 Mikael Magnusson <mikachu@gmail.com> + + * 45796: Src/subst.c: Support ${name:offset:length} with an + empty offset + 2020-05-09: Eitan Adler <lists@eitanadler.com> * noraj: gitlab !13: Completion/Unix/Type/_tar_archive: libarchive and diff --git a/Src/subst.c b/Src/subst.c index 94ddb9ceb..90b5fc121 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1565,6 +1565,11 @@ check_colon_subscript(char *str, char **endp) if (!*str || ialpha(*str) || *str == '&') return NULL; + if (*str == ':') { + *endp = str; + return dupstring("0"); + } + *endp = parse_subscript(str, 0, ':'); if (!*endp) { /* No trailing colon? */ @@ -1575,8 +1580,10 @@ check_colon_subscript(char *str, char **endp) sav = **endp; **endp = '\0'; str = dupstring(str); - if (parsestr(&str)) + if (parsestr(&str)) { + **endp = sav; return NULL; + } singsub(&str); remnulargs(str); untokenize(str); @@ -2781,7 +2788,6 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } if (bct) { - noclosebrace: zerr("closing brace expected"); return NULL; } @@ -2937,9 +2943,12 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } break; case ':': - /* this must be `::=', unconditional assignment */ - if (*s != '=' && *s != Equals) - goto noclosebrace; + /* this could be either `::=', unconditional assignment + * or a ${name:offset:length} with an empty offset */ + if (*s != '=' && *s != Equals) { + s -= 1; + goto colonsubscript; + } vunset = 1; s++; /* Fall through */ @@ -3282,6 +3291,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * if there isn't a trailing modifier? Why don't we do this * e.g. when we handle the ${(t)...} flag? */ +colonsubscript: if (chkset) { val = dupstring(vunset ? "0" : "1"); isarr = 0; |