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

querify doesn't encode single quotes correctly #11695

Closed
ys opened this issue Nov 10, 2023 · 10 comments
Closed

querify doesn't encode single quotes correctly #11695

ys opened this issue Nov 10, 2023 · 10 comments

Comments

@ys
Copy link

ys commented Nov 10, 2023

What version of Hugo are you using (hugo version)? 0.120.4

Does this issue reproduce with the latest release? Yes

When doing querify "lol" .Summary on a page with a summary: Mon labo me le disait, y’a quelque chose de bizarre dans tes expositions.

The encoded string is lol=Mon+labo+me+le+disait%2C+y%26rsquo%3Ba+quelque+chose+de+bizarre+dans+tes+expositions.

%26rsquo%3B which is ’ but should be %27. Which is the correct way to URL encode apostrophe or single quote I think.

@jmooring
Copy link
Member

On this page, how is the summary defined? Automatically, manually (using <!--more-->), or in front matter?

@ys
Copy link
Author

ys commented Nov 10, 2023

@ys
Copy link
Author

ys commented Nov 10, 2023

@ys
Copy link
Author

ys commented Nov 10, 2023

I just tested url.Values encode method on https://pkg.go.dev/net/url#Values.Encode and it correctly encode it to %27

@jmooring
Copy link
Member

The problem you are experiencing is closely related to #8910 (comment). Regardless of how you define the summary, it is passed through the markdown renderer, which converts certain punctuation characters to HTML entities.

The querify function is behaving as expected/desired. For example:

{{ querify "a" "b'c" }} --> a=b%27c 

Option 1

For a summary defined in front matter, you can access the raw value with:

{{ querify "lol" .Params.Summary }}

But I'm not sure how forward-compatible that's going to be. See #11055.

Option 2

Change the character substitution rules in your site configuration:

[markup.goldmark.extensions.typographer]
apostrophe = "'"
leftSingleQuote = "'"
rightSingleQuote = "'"

Option 3

Disable the typographer extension:

[markup.goldmark.extensions.typographer]
disable = true

Option 4

Use a different front matter field, such as description:

{{ querify "lol" .Description }}

To summarize, the querify function encodes single quotes correctly. The problem is that your code is feeding it an HTML entity.

@ys
Copy link
Author

ys commented Nov 10, 2023

Wow, thanks so much, it makes a lot more sense then... Will pick an option.
Thanks for the many ones!

Glad it is me and not the code...

@ys ys closed this as completed Nov 10, 2023
@ys
Copy link
Author

ys commented Nov 10, 2023

It looks like that .Description suffers a similar fate... it ends up as %26%2339%3B

@ys
Copy link
Author

ys commented Nov 10, 2023

Nevermind, it is because I use truncate...

@jmooring
Copy link
Member

{{ querify "a" ("b'c" | safeHTML | truncate 42) }}

https://gohugo.io/functions/strings/truncate/

Copy link

github-actions bot commented Dec 2, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants