diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-07-04 09:05:29 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-07-04 10:09:18 +0200 |
commit | 8cf96f244ad710fa02c3f9729fef5a1bedb7632a (patch) | |
tree | 14ec82a410b8bdb6a5e19497ce7e171a9419fe25 /hugolib | |
parent | 82af94d1f56b36a99be4f6c55697d105cee9dd84 (diff) | |
download | hugo-8cf96f244ad710fa02c3f9729fef5a1bedb7632a.tar.gz hugo-8cf96f244ad710fa02c3f9729fef5a1bedb7632a.zip |
Fix site.GetPage, never do short lookups for paths with leadig slash
Fixes #12638
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/pagecollections.go | 9 | ||||
-rw-r--r-- | hugolib/pagecollections_test.go | 29 |
2 files changed, 30 insertions, 8 deletions
diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go index 5ed2a28f0..f1038deff 100644 --- a/hugolib/pagecollections.go +++ b/hugolib/pagecollections.go @@ -110,11 +110,6 @@ func (c *pageFinder) getPageForRefs(ref ...string) (page.Page, error) { key = refs[1] } - key = filepath.ToSlash(key) - if !strings.HasPrefix(key, "/") { - key = "/" + key - } - return c.getPage(nil, key) } @@ -211,9 +206,7 @@ func (c *pageFinder) getContentNodeForRef(context page.Page, isReflink, hadExten var doSimpleLookup bool if isReflink || context == nil { slashCount := strings.Count(inRef, "/") - if slashCount <= 1 { - doSimpleLookup = slashCount == 0 || ref[0] == '/' - } + doSimpleLookup = slashCount == 0 } if !doSimpleLookup { diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index 96f1afe3d..692ae9ef6 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -413,6 +413,35 @@ layout: p2 b.AssertFileContent("public/s1/p2/index.html", "p1") } +func TestGetPageNewsVsTagsNewsIssue12638(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['rss','section','sitemap'] +[taxonomies] + tag = "tags" +-- content/p1.md -- +--- +title: p1 +tags: [news] +--- +-- layouts/index.html -- +/tags/news: {{ with .Site.GetPage "/tags/news" }}{{ .Title }}{{ end }}| +news: {{ with .Site.GetPage "news" }}{{ .Title }}{{ end }}| +/news: {{ with .Site.GetPage "/news" }}{{ .Title }}{{ end }}| + +` + + b := Test(t, files) + + b.AssertFileContent("public/index.html", + "/tags/news: News|", + "news: News|", + "/news: |", + ) +} + func TestGetPageBundleToRegular(t *testing.T) { files := ` -- hugo.toml -- |