Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add url encode and decode functions #248

Open
dm3ch opened this issue May 21, 2020 · 3 comments
Open

Add url encode and decode functions #248

dm3ch opened this issue May 21, 2020 · 3 comments

Comments

@dm3ch
Copy link

dm3ch commented May 21, 2020

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

@afduarte
Copy link

afduarte commented Oct 7, 2020

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)

@mik-laj
Copy link

mik-laj commented May 23, 2021

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: apache/airflow#16004

@mik-laj
Copy link

mik-laj commented May 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants