1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

Merge pull request #2376 from Ryooooooga/fix-resolve-placeholder

This commit is contained in:
Jesse Duffield 2023-01-26 13:03:19 +11:00 committed by GitHub
commit b942df02a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -22,9 +22,12 @@ func ResolveTemplate(templateStr string, object interface{}, funcs template.Func
// ResolvePlaceholderString populates a template with values
func ResolvePlaceholderString(str string, arguments map[string]string) string {
oldnews := make([]string, 0, len(arguments)*4)
for key, value := range arguments {
str = strings.Replace(str, "{{"+key+"}}", value, -1)
str = strings.Replace(str, "{{."+key+"}}", value, -1)
oldnews = append(oldnews,
"{{"+key+"}}", value,
"{{."+key+"}}", value,
)
}
return str
return strings.NewReplacer(oldnews...).Replace(str)
}

View File

@ -53,6 +53,13 @@ func TestResolvePlaceholderString(t *testing.T) {
},
"{{}} {{ this }} { should not throw}} an {{{{}}}} error",
},
{
"{{a}}",
map[string]string{
"a": "X{{.a}}X",
},
"X{{.a}}X",
},
}
for _, s := range scenarios {