mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
resources/page: Escape hash sign in permalinks
When creating a link to a file with a `#` in the filename, the link gets truncated. This happens because the filename is eventaully passed to `url.Parse` which (correctly!) interprets the `#` as fragment separator. This commit escapes the `#` in the filename before creating the link. Fixes #4926 Fixes #8232 Fixes #12342 Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>
This commit is contained in:
parent
060cce0a91
commit
4500b0e423
2 changed files with 62 additions and 0 deletions
|
@ -268,6 +268,13 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
|
|||
tp.SubResourceBaseTarget = pb.PathDir()
|
||||
tp.SubResourceBaseLink = pb.LinkDir()
|
||||
}
|
||||
|
||||
// paths.{URL,Path}Escape rely on url.Parse which
|
||||
// will consider # a fragment identifier, so it and
|
||||
// and everything after it will be stripped from
|
||||
// `link`, so we need to escape it first.
|
||||
link = strings.ReplaceAll(link, "#", "%23")
|
||||
|
||||
if d.URL != "" {
|
||||
tp.Link = paths.URLEscape(link)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue