]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix relref regression with trailing slash
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 21 Feb 2024 14:42:00 +0000 (15:42 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 21 Feb 2024 16:27:45 +0000 (17:27 +0100)
Fixes #12096

hugolib/pagecollections.go
hugolib/site_test.go

index 58c646334b4e768bde96b52386447efff8be3ca1..3783dadab889133094d5dd8d7260d46e03480cd8 100644 (file)
@@ -56,7 +56,7 @@ func (c *pageFinder) getPageRef(context page.Page, ref string) (page.Page, error
 }
 
 func (c *pageFinder) getPage(context page.Page, ref string) (page.Page, error) {
-       n, err := c.getContentNode(context, false, paths.ToSlashTrimTrailing(ref))
+       n, err := c.getContentNode(context, false, ref)
        if err != nil {
                return nil, err
        }
@@ -121,6 +121,7 @@ func (c *pageFinder) getPageForRefs(ref ...string) (page.Page, error) {
 const defaultContentExt = ".md"
 
 func (c *pageFinder) getContentNode(context page.Page, isReflink bool, ref string) (contentNodeI, error) {
+       ref = paths.ToSlashTrimTrailing(ref)
        inRef := ref
        if ref == "" {
                ref = "/"
index 63088ee8829d0b6e6caa5e2dcf4fa3ada1231bbb..1de1d688a699a7e40b1da7b5414a44303bd8f5f2 100644 (file)
@@ -992,6 +992,28 @@ func TestRefLinking(t *testing.T) {
        // TODO: and then the failure cases.
 }
 
+func TestRelRefWithTrailingSlash(t *testing.T) {
+       files := `
+-- hugo.toml --
+-- content/docs/5.3/examples/_index.md --
+---
+title: "Examples"
+---
+-- content/_index.md --
+---
+title: "Home"
+---
+
+Examples: {{< relref "/docs/5.3/examples/" >}}
+-- layouts/home.html --
+Content: {{ .Content }}|
+`
+
+       b := Test(t, files)
+
+       b.AssertFileContent("public/index.html", "Examples: /docs/5.3/examples/")
+}
+
 func checkLinkCase(site *Site, link string, currentPage page.Page, relative bool, outputFormat string, expected string, t *testing.T, i int) {
        t.Helper()
        if out, err := site.refLink(link, currentPage, relative, outputFormat); err != nil || out != expected {