From: Agniva De Sarker Date: Wed, 28 Mar 2018 08:15:26 +0000 (+0530) Subject: os: keep the $ if a variable is not detected X-Git-Tag: go1.11beta1~1068 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7bf631e1fc55839a6bff404a91597326e1addc10;p=gostls13.git os: keep the $ if a variable is not detected 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/os/env.go b/src/os/env.go index 4e0171f408..b3b615cb33 100644 --- a/src/os/env.go +++ b/src/os/env.go @@ -21,7 +21,12 @@ func Expand(s string, mapping func(string) string) string { 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 } diff --git a/src/os/env_test.go b/src/os/env_test.go index 16f1945638..78c8fe57cb 100644 --- a/src/os/env_test.go +++ b/src/os/env_test.go @@ -49,6 +49,8 @@ var expandTests = []struct { {"${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) {