summaryrefslogtreecommitdiffstats
path: root/resources/page/page_paths.go
diff options
context:
space:
mode:
authorSoren L. Hansen <sorenisanerd@gmail.com>2024-04-04 13:31:20 -0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-04-05 15:57:02 +0200
commit4500b0e423a2c58e6e54526d0d02d2924cc774b6 (patch)
tree21ea70f023d7614c67d84f2dda8a841031b5db02 /resources/page/page_paths.go
parent060cce0a910ffd9dc4e92efbe758fc5f187c3145 (diff)
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>
Diffstat (limited to 'resources/page/page_paths.go')
-rw-r--r--resources/page/page_paths.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/resources/page/page_paths.go b/resources/page/page_paths.go
index 8052287c6..4826ed5f9 100644
--- a/resources/page/page_paths.go
+++ b/resources/page/page_paths.go
@@ -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 {