Skip to content

Commit

Permalink
Fix resources.GetMatch, resources.Match, and resources.ByType to they…
Browse files Browse the repository at this point in the history
… don't normalize permalinks

Fixes #12182
  • Loading branch information
bep committed Mar 1, 2024
1 parent 9dfa9e7 commit 7023cf0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/resource_factories/create/create.go
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tpl/resources/resources_integration_test.go
Expand Up @@ -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|
`)
}

0 comments on commit 7023cf0

Please sign in to comment.