mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
fix: fix ReplacePlaceholderString
This commit is contained in:
parent
48df9b7f4e
commit
7149cfeb11
@ -22,9 +22,12 @@ func ResolveTemplate(templateStr string, object interface{}, funcs template.Func
|
|||||||
|
|
||||||
// ResolvePlaceholderString populates a template with values
|
// ResolvePlaceholderString populates a template with values
|
||||||
func ResolvePlaceholderString(str string, arguments map[string]string) string {
|
func ResolvePlaceholderString(str string, arguments map[string]string) string {
|
||||||
|
oldnews := make([]string, 0, len(arguments)*4)
|
||||||
for key, value := range arguments {
|
for key, value := range arguments {
|
||||||
str = strings.Replace(str, "{{"+key+"}}", value, -1)
|
oldnews = append(oldnews,
|
||||||
str = strings.Replace(str, "{{."+key+"}}", value, -1)
|
"{{"+key+"}}", value,
|
||||||
|
"{{."+key+"}}", value,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return str
|
return strings.NewReplacer(oldnews...).Replace(str)
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,13 @@ func TestResolvePlaceholderString(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"{{}} {{ this }} { should not throw}} an {{{{}}}} error",
|
"{{}} {{ this }} { should not throw}} an {{{{}}}} error",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"{{a}}",
|
||||||
|
map[string]string{
|
||||||
|
"a": "X{{.a}}X",
|
||||||
|
},
|
||||||
|
"X{{.a}}X",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user