-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: encoding of quotes in Page Sharer URL #2726
Conversation
✅ Deploy Preview for hugo-portfolio-theme ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for markdown-slides ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Thanks for spotting this issue with using Hugo's htmlEscape and proposing using urlquery instead. Note: the urlquery function appears to be an undocumented Hugo feature as well as a Go function: gohugoio/hugoDocs#1627 (comment) |
Yep, I couldn't find anything on https://gohugo.io/functions/ EDIT: just saw you said it's also an undocumented Hugo feature! That I didn't know haha |
Does this fix this issue without doing anything extra? |
Yes! As far as I tested that should be enough to fix that. |
Purpose
Change the way url and title are encoded for sharing posts. Originally
htmlEscape
was used; however, it only escapes few characters and it breaks the generated urls.For example, if a post title was "What's in today?", the quote
'
would be encoded as'
which broke the link.Besides that,
htmlEscape
only tried to fix few characters.So instead of using
(i.e., space) as
htmlEscape
we should useurlquery
which encodes all characters that are required in the string.However,
urlquery
encodes+
as%2B
and+
:https://cs.opensource.google/go/go/+/refs/tags/go1.18.2:src/net/url/url.go;drc=7791e934c882fd103357448aee0fd577b20013ce;l=285
Because of this
mailto
links were still having trouble with + and spaces, so we re-encode the "+spaces" into%20
, so they decode correctly formailto
.