sprig icon indicating copy to clipboard operation
sprig copied to clipboard

Add url encode and decode functions

Open dm3ch opened this issue 5 years ago • 3 comments

Helm is using sprig as a source of extended functions.

In helm url encode and decode functions would be useful i think. So it would be great to add them to sprig.

P.S. For example it would be extremely useful in gitlab chart MR - https://gitlab.com/gitlab-org/charts/gitlab/-/merge_requests/1234

dm3ch avatar May 21 '20 21:05 dm3ch

Just here to +1 this, for anyone looking for a solution, remember you can always add your custom functions to the function map:

func urlDecode(str string) string           { s, _ := url.QueryUnescape(str); return s }
func urlEncode(str string) string           { return url.QueryEscape(str) }

fmap := sprig.TxtFuncMap()
fmap["urlEncode"] = urlEncode
fmap["urlDecode"] = urlDecode
// then use like:
template.New("").Funcs(fmap).Parse(yourTemplate)

afduarte avatar Oct 07 '20 11:10 afduarte

In Apache Airflow, we need to build the URL from the values from the values.yaml file, but unfortunately this cannot be done because to build the URL with userinfo we need a function that percent-encode the usernaame/password. More context: https://github.com/apache/airflow/pull/16004

mik-laj avatar May 23 '21 02:05 mik-laj

I found a workaround. Go templaes supports urlquery function. It returns the escaped version of the value passed in as an argument so that it is suitable for embedding in the query portion of a URL.

mik-laj avatar May 23 '21 12:05 mik-laj