Skip to content

Commit 8cf96f2

Browse files
committed
Fix site.GetPage, never do short lookups for paths with leadig slash
Fixes #12638
1 parent 82af94d commit 8cf96f2

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

hugolib/pagecollections.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ func (c *pageFinder) getPageForRefs(ref ...string) (page.Page, error) {
110110
key = refs[1]
111111
}
112112

113-
key = filepath.ToSlash(key)
114-
if !strings.HasPrefix(key, "/") {
115-
key = "/" + key
116-
}
117-
118113
return c.getPage(nil, key)
119114
}
120115

@@ -211,9 +206,7 @@ func (c *pageFinder) getContentNodeForRef(context page.Page, isReflink, hadExten
211206
var doSimpleLookup bool
212207
if isReflink || context == nil {
213208
slashCount := strings.Count(inRef, "/")
214-
if slashCount <= 1 {
215-
doSimpleLookup = slashCount == 0 || ref[0] == '/'
216-
}
209+
doSimpleLookup = slashCount == 0
217210
}
218211

219212
if !doSimpleLookup {

hugolib/pagecollections_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,35 @@ layout: p2
413413
b.AssertFileContent("public/s1/p2/index.html", "p1")
414414
}
415415

416+
func TestGetPageNewsVsTagsNewsIssue12638(t *testing.T) {
417+
t.Parallel()
418+
419+
files := `
420+
-- hugo.toml --
421+
disableKinds = ['rss','section','sitemap']
422+
[taxonomies]
423+
tag = "tags"
424+
-- content/p1.md --
425+
---
426+
title: p1
427+
tags: [news]
428+
---
429+
-- layouts/index.html --
430+
/tags/news: {{ with .Site.GetPage "/tags/news" }}{{ .Title }}{{ end }}|
431+
news: {{ with .Site.GetPage "news" }}{{ .Title }}{{ end }}|
432+
/news: {{ with .Site.GetPage "/news" }}{{ .Title }}{{ end }}|
433+
434+
`
435+
436+
b := Test(t, files)
437+
438+
b.AssertFileContent("public/index.html",
439+
"/tags/news: News|",
440+
"news: News|",
441+
"/news: |",
442+
)
443+
}
444+
416445
func TestGetPageBundleToRegular(t *testing.T) {
417446
files := `
418447
-- hugo.toml --

0 commit comments

Comments
 (0)