summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatowTakeshi <[email protected]>2020-11-22 02:58:26 +0900
committerBjørn Erik Pedersen <[email protected]>2020-11-21 23:37:58 +0100
commite4fcb672ed8bae21fd9780292b54fea3040dd877 (patch)
tree7d95e9f5d7bcc050a8242f7893f39cd86b1bb914
parent18c13adcd46bdff963311fdba9eaa9b5a299106e (diff)
downloadhugo-e4fcb672ed8bae21fd9780292b54fea3040dd877.tar.gz
hugo-e4fcb672ed8bae21fd9780292b54fea3040dd877.zip
resources: Preserve url set in frontmatter without sanitizing
related #6007 (already closed)
-rw-r--r--resources/page/page_paths.go16
-rw-r--r--resources/page/page_paths_test.go7
2 files changed, 17 insertions, 6 deletions
diff --git a/resources/page/page_paths.go b/resources/page/page_paths.go
index 247c4dfcb..6ef9bced6 100644
--- a/resources/page/page_paths.go
+++ b/resources/page/page_paths.go
@@ -308,12 +308,16 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
linkDir = strings.TrimSuffix(path.Join(slash, linkDir), slash)
- // Note: MakePathSanitized will lower case the path if
- // disablePathToLower isn't set.
- pagePath = d.PathSpec.MakePathSanitized(pagePath)
- pagePathDir = d.PathSpec.MakePathSanitized(pagePathDir)
- link = d.PathSpec.MakePathSanitized(link)
- linkDir = d.PathSpec.MakePathSanitized(linkDir)
+ // if page URL is explicitly set in frontmatter,
+ // preserve its value without sanitization
+ if d.Kind != KindPage || d.URL == "" {
+ // Note: MakePathSanitized will lower case the path if
+ // disablePathToLower isn't set.
+ pagePath = d.PathSpec.MakePathSanitized(pagePath)
+ pagePathDir = d.PathSpec.MakePathSanitized(pagePathDir)
+ link = d.PathSpec.MakePathSanitized(link)
+ linkDir = d.PathSpec.MakePathSanitized(linkDir)
+ }
tp.TargetFilename = filepath.FromSlash(pagePath)
tp.SubResourceBaseTarget = filepath.FromSlash(pagePathDir)
diff --git a/resources/page/page_paths_test.go b/resources/page/page_paths_test.go
index 63df48a99..53f8b80ef 100644
--- a/resources/page/page_paths_test.go
+++ b/resources/page/page_paths_test.go
@@ -130,6 +130,13 @@ func TestPageTargetPath(t *testing.T) {
URL: "/some/other/path",
Type: output.HTMLFormat}, TargetPaths{TargetFilename: "/some/other/path/index.html", SubResourceBaseTarget: "/some/other/path", Link: "/some/other/path/"}},
{
+ "HTML page with URL containing double hyphen", TargetPathDescriptor{
+ Kind: KindPage,
+ Dir: "/sect/",
+ BaseName: "mypage",
+ URL: "/some/other--url/",
+ Type: output.HTMLFormat}, TargetPaths{TargetFilename: "/some/other--url/index.html", SubResourceBaseTarget: "/some/other--url", Link: "/some/other--url/"}},
+ {
"HTML page with expanded permalink", TargetPathDescriptor{
Kind: KindPage,
Dir: "/a/b",