]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix site.GetPage, never do short lookups for paths with leadig slash
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 4 Jul 2024 07:05:29 +0000 (09:05 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 4 Jul 2024 08:09:18 +0000 (10:09 +0200)
Fixes #12638

hugolib/pagecollections.go
hugolib/pagecollections_test.go

index 5ed2a28f038429afe3f7afe4f8ae146b22bc3de3..f1038deffe82a186ca5e85e2a6f4d14003a763ef 100644 (file)
@@ -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 {
index 96f1afe3d19c13d9ec65c6ca79d6e367de7c07a8..692ae9ef6b920efdaca6335fcf006d3c1a9c8736 100644 (file)
@@ -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 --