From 7023cf0f07d07bd943404d88d5fc8f3c5f7c9cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 1 Mar 2024 11:47:16 +0100 Subject: Fix resources.GetMatch, resources.Match, and resources.ByType to they don't normalize permalinks Fixes #12182 --- resources/resource_factories/create/create.go | 2 +- tpl/resources/resources_integration_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go index 0cf84c49b..ac1a2af07 100644 --- a/resources/resource_factories/create/create.go +++ b/resources/resource_factories/create/create.go @@ -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 diff --git a/tpl/resources/resources_integration_test.go b/tpl/resources/resources_integration_test.go index 5a3c29666..d72b13507 100644 --- a/tpl/resources/resources_integration_test.go +++ b/tpl/resources/resources_integration_test.go @@ -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| + + `) +} -- cgit v1.2.3