resources: Preserve url set in frontmatter without sanitizing
authorSatowTakeshi <doublequotation@gmail.com>
Sat, 21 Nov 2020 17:58:26 +0000 (02:58 +0900)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 21 Nov 2020 22:37:58 +0000 (23:37 +0100)
related #6007 (already closed)

resources/page/page_paths.go
resources/page/page_paths_test.go

index 247c4dfcbfca4e1e6db789adc311da2db284fa62..6ef9bced60a9a09254ab8c97a25ddadcaf9f3e5b 100644 (file)
@@ -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)
index 63df48a99f464310139f76b9b646e15dcca144f9..53f8b80ef45e531027eeb3c172dbac55515397d4 100644 (file)
@@ -129,6 +129,13 @@ func TestPageTargetPath(t *testing.T) {
                                                        BaseName: "mypage",
                                                        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,