If the character after $ cannot be detected as a valid
variable declaration, do not gobble the $.
Fixes #24345
Change-Id: Iec47be1f2e4f8147b8ceb64c30778eae8045b58f
Reviewed-on: https://go-review.googlesource.com/103055
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
if s[j] == '$' && j+1 < len(s) {
buf = append(buf, s[i:j]...)
name, w := getShellName(s[j+1:])
- buf = append(buf, mapping(name)...)
+ // If the name is empty, keep the $.
+ if name == "" {
+ buf = append(buf, s[j])
+ } else {
+ buf = append(buf, mapping(name)...)
+ }
j += w
i = j + 1
}
{"${HOME}", "/usr/gopher"},
{"${H}OME", "(Value of H)OME"},
{"A$$$#$1$H$home_1*B", "APIDNARGSARGUMENT1(Value of H)/usr/foo*B"},
+ {"start$+middle$^end$", "start$+middle$^end$"},
+ {"mixed$|bag$$$", "mixed$|bagPID$"},
}
func TestExpand(t *testing.T) {