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 encoding/decoding functions #62

Closed
wants to merge 1 commit into from
Closed

add url encoding/decoding functions #62

wants to merge 1 commit into from

Conversation

krancour
Copy link
Contributor

@krancour krancour commented Oct 19, 2017

Also, this grows the number of encoding/decoding functions to a point where I felt it was useful to split those functions out of strings.go into a new file encoding.go-- same for the corresponding tests.

}

func urlEncode(v string) string {
return url.QueryEscape(v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the use case for urlEncode?

To provide a little context...

  1. url.QueryEscape isn't meant for a full URL. Instead, it's meant for the Query string part of it.
  2. The html/template package does automatic URL escaping. If you want to learn more about that see the escape.go and url.go files.

So, this function (once for full URLs) would need a case outside of html templates.

Copy link
Contributor Author

@krancour krancour Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.QueryEscape isn't meant for a full URL. Instead, it's meant for the Query string part of it.

This is both true and false. I think what you're saying is that if you encode http://www.example.com, you're going to end up with http%3A%2F%2Fwww.example.com, and you're absolutely right-- but it's probably not correct that nobody ever wants to do that. Imagine, for instance, the case where a URL needs to be passed as a query parameter within another url.

Although the above isn't my actual use case. It's just a good example. My real case is that I want to URL encode a password that some off-the-shelf software internally concatenates into a connection string without (shame on them) properly URL encoding it themselves.

I think whether we are talking about sprig template functions or just plain url.QueryEscape in go, what you do with it is relative to one's use case. It's probably not for us to decide how it's used, but rather just to provide the capability.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need this to be able to create custom urls.

My goal is to create URL which would redirect to prometheus, e.g.:

https://prometheus.company.com/graph?g0.range_input=1h&g0.expr={{ urlEnc .query }}&g0.tab=1

@krancour
Copy link
Contributor Author

Well... I just realized this won't actually help me because the value I want to encode is in a k8s secret. I can use the downward API to shim it into an env var, but I can't actually get at its value to carry out this encoding.

I do still think this is generally useful functionality, but it's not longer important to me.

@mattfarina I leave it to you whether you'd like to just close this.

@andig
Copy link

andig commented Jun 16, 2023

I do still think this is generally useful functionality, but it's not longer important to me.

That's too bad.

My real case is that I want to URL encode a password

That's exactly what I would need to do, too.

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

Successfully merging this pull request may close these issues.

4 participants