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

Question about urlquery #7

Closed
brycewray opened this issue Sep 10, 2022 · 2 comments
Closed

Question about urlquery #7

brycewray opened this issue Sep 10, 2022 · 2 comments

Comments

@brycewray
Copy link

Hello. I read your post, “Percent-encoding with the Hugo urlquery Function” (as well as your answer in the Hugo Discourse) regarding the urlquery function you discovered in Hugo. Nice detective work! However, when I use urlquery on a string, the spaces all come out as + HTML entities rather than %20 characters as I’d hoped would be the case based on your information. Other characters seem to have the %-style encoding I’d expect. Am I missing something? Thanks in advance for whatever time you can give to provide your thoughts on this.

@schnerring
Copy link
Owner

schnerring commented Sep 12, 2022

I tested around a bit and for me everything works as expected. Here are my questions that come to mind:

  • Is it a platform issue (Linux/Windows)?
  • Is it a golang/Hugo version issue?
  • Is it a browser issue?
  • Is the urlquery result altered by another Hugo function afterwards?

You can directly input a test string in the golang docs under Example here: https://pkg.go.dev/net/url#QueryEscape

Does this return the expected result? If I input ho ho ho, it returns ho+ho+ho as expected.

You can find the implementation (v1.19.1) here: https://cs.opensource.google/go/go/+/refs/tags/go1.19.1:src/net/url/url.go;l=275

Using {{ urlquery "ho ho ho" }} yields the same result. To make sure it's not altered by other Hugo functions, I inserted the snippet directly after the <body> tag inside baseof.html. I tried messing it up by piping it into other Hugo functions like safeHTML or htmlEscape but couldn't get the same result you got.

@brycewray
Copy link
Author

Yes, it’s a puzzle. (Using macOS in my case, re your first bullet above.) In any event, I’d still need to do some replace or replaceRE work because the target API (Cloudinary’s) need %-style escaping in all cases; so I suppose it’s a non-issue. Anyway, thanks for the reply, links, and research!

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

2 participants