Commit ea19241f authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Support encoding of $ in variables: accept $$

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/12793
parent ee9607b7
Pipeline #673596 passed with stages
......@@ -38,6 +38,12 @@ func (b BuildVariables) StringList() (variables []string) {
}
func (b BuildVariables) Get(key string) string {
switch key {
case "$":
return key
case "*", "#", "@", "!", "?", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
return ""
}
for i := len(b) - 1; i >= 0; i-- {
if b[i].Key == key {
return b[i].Value
......
......@@ -62,3 +62,19 @@ func TestVariablesExpansion(t *testing.T) {
assert.Equal(t, expanded.Get("private"), "value_of_value_of_$undefined")
assert.Equal(t, expanded.ExpandValue("${public} ${private}"), "value_of_ value_of_value_of_$undefined")
}
func TestSpecialVariablesExpansion(t *testing.T) {
all := BuildVariables{
{"key", "$$", false, false, false},
{"key2", "$/dsa", true, false, false},
{"key3", "aa$@bb", false, false, false},
{"key4", "aa${@}bb", false, false, false},
}
expanded := all.Expand()
assert.Len(t, expanded, 4)
assert.Equal(t, expanded.Get("key"), "$")
assert.Equal(t, expanded.Get("key2"), "/dsa")
assert.Equal(t, expanded.Get("key3"), "aabb")
assert.Equal(t, expanded.Get("key4"), "aabb")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment