]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix resources.GetMatch, resources.Match, and resources.ByType to they don't normalize...
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 1 Mar 2024 10:47:16 +0000 (11:47 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 1 Mar 2024 12:34:05 +0000 (13:34 +0100)
Fixes #12182

resources/resource_factories/create/create.go
tpl/resources/resources_integration_test.go

index 0cf84c49b9c49869ce268ac92d85409dc939fd81..ac1a2af0777a93758a336bacb477a3f63c8f5364 100644 (file)
@@ -134,7 +134,7 @@ func (c *Client) match(name, pattern string, matchFunc func(r resource.Resource)
                                        return meta.Open()
                                },
                                GroupIdentity: meta.PathInfo,
-                               TargetPath:    meta.PathInfo.PathNoLang(),
+                               TargetPath:    meta.PathInfo.Unnormalized().Path(),
                        })
                        if err != nil {
                                return true, err
index 5a3c296665a4e30541ff65b1287f5938a5e71b38..d72b1350729dece883e231c415d2462ecc5b5606 100644 (file)
@@ -116,3 +116,30 @@ Empty string not found
 
                `)
 }
+
+func TestResourcesGettersShouldNotNormalizePermalinks(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- config.toml --
+baseURL = "http://example.com/"
+-- assets/401K Prospectus.txt --
+Prospectus.
+-- layouts/index.html --
+{{ $name := "401K Prospectus.txt" }}
+Get: {{ with resources.Get $name }}{{ .RelPermalink }}|{{ .Permalink }}|{{ end }}
+GetMatch: {{ with resources.GetMatch $name }}{{ .RelPermalink }}|{{ .Permalink }}|{{ end }}
+Match: {{ with (index (resources.Match $name) 0) }}{{ .RelPermalink }}|{{ .Permalink }}|{{ end }}
+ByType: {{ with (index (resources.ByType "text") 0) }}{{ .RelPermalink }}|{{ .Permalink }}|{{ end }}
+       `
+
+       b := hugolib.Test(t, files)
+
+       b.AssertFileContent("public/index.html", `
+Get: /401K%20Prospectus.txt|http://example.com/401K%20Prospectus.txt|
+GetMatch: /401K%20Prospectus.txt|http://example.com/401K%20Prospectus.txt|
+Match: /401K%20Prospectus.txt|http://example.com/401K%20Prospectus.txt|
+ByType: /401K%20Prospectus.txt|http://example.com/401K%20Prospectus.txt|
+
+               `)
+}