Initially posed a question in the forum: https://discourse.gohugo.io/t/hash-pound-sign-not-escaped-in-title-permalink-breaking-urls/12825
This seems really strange to me as a default behavior, and feels like a bug. Allow me to asplain?
I have a post title, like tcg's series of posts #1.
The Permalinks configuration examples in the docs contain the following example:
post = "/:year/:month/:title/"
... which lead me to believe that this would pretty much automatically work for my not-unreasonable post titles. ("work" here meaning "escape the URL for .Permalink and filename value automatically).
In the forum, maiki suggested that I might use :slug as a workaround, meaning that I would need to always manually provide :slug.
Also, the aforementioned docs says this about :slug:
the content’s slug (or title if no slug is provided in the front matter)
Meaning that it will always fall back to :title if I fail to provide a slug. Which seems to me like I always have to be sure to manually provide a URL-friendly value... as a human, writing a document. That doesn't feel right.
I think this is a bug. (Sadly, I am not yet familiar enough with Go to find a spot and try to offer a PR for the expected behavior).
I am willing to be wrong, and understand I may be Doing It Wrong.
EDIT:
Using versions 0.42.2 and 0.43, on macOS
Confirmed, same issue on my machine.
Causes Netlify to fail as well:
9:37:37 PM: failed during stage 'deploying site': Invalid filename 'blog/1/01/01/home-assistant-podcast-#9/index.html'. Deployed filenames cannot contain # or ? characters
I've even used :slug, which renders the same issue.
Assuming this would be fixed by #4388.
Great news! Hope to see it in soon!
I saw https://github.com/gohugoio/hugo/pull/4388 was merged, and I am assuming it made it into v0.48, is that correct?
On the site where I've run into this the most, I'm not seeing this fixed, if that's the case. Or has that merge not made it into a release? 🤷♂️ Just wanted to get this closed if it was fixed, but I'm not sure if that's the case.
On the site where I've run into this the most, I'm not seeing this fixed, if that's the case. Or has that merge not made it into a release?
According to the release notes it's included in Hugo 0.48. The issue is the third bullet point in the 'Fixes' part of the 0.48 release notes.
It seems that this issue was not closed when #4388 was merged.
I can reproduce in Hugo 0.48
In the meantime @tcg you can always remove the hash # from the Permalink string in your templates with the replaceRE function.
@onedrawingperday Thanks for the suggestion. I think I mentioned previously how I'm working around it. Specifically on one site, I am manually specifying the url value for the posts in question, to work around .Permalink containing a bad value (when set to :title).
I'm of the opinion that the Theme code shouldn't necessarily concern itself with fixing permalink values, etc.
Status Update:
We committed PR #5170 to fix this issue, but it was reverted due to the fact that it broke stuff (see #5223). There seems to be some confusion in #5223 about testing against @onedrawingperday's test repo. I don't think I ever tested #5170 against that repo. My testing of that repo was against PR #4388.
I'm hoping to get some free time soon to take another look at these issues.
I know that #5170 was not tested against my test repo (I never requested it and also I had removed the repo from GitHub).
Anyway it's a good thing that I am on the latest Hugo DEV so that I can see if PRs break things before they make it into a release.
I will keep an eye on this issue and any PR that will address it.
I still have this issue on Hugo Static Site Generator v0.54.0/extended linux/amd64 BuildDate: unknown
{{ .RelPermalink }} can return a link with a non-escaped hashtag.
I'm having the same issue. This is causing our sites to break!
I guess the fix for this was reverted because it broke other stuff. I'm reopening this and closing the other.
Same issue for me as well
I've just bump into this issue. Changing posts = "/:year/:month/:day/:title/" to posts = "/:year/:month/:day/:slug/" helps, but it took me a moment to find it (the documentation doesn't explain difference between title and slug in the context of quoting).
I have the same problem with '#' in a taxonomy
For instance I have a series taxonomy, and one of my posts has the value "Things every C# developer should know" for this taxonomy. Unfortunately the .RelPermalink of the taxonomy page returns /series/things-every-c#-developer-should-know/. The correct permalink should be /series/things-every-c%23-developer-should-know/
Just ran into this as well, with a tag that starts with a hashtag. Using
replaceRE "#" "%23" .Permalink
fixes it, but that only handles one page, and doesn't handle the taxonomy list and other places.