Repository: gohugoio/hugo (language: go)

Issue:
resources.GetMatch, resources.Match, and resources.ByType anchorize and lowercase resource permalinks
Maybe this isn't so important with images, but it is very important with things like:

```
assets/
├── 401K Prospectus.pdf
├── Employment Agreement.pdf
└── Non-disclosure Agreement.pdf
```

#### resources.Get (PASS)

```
{{ with resources.Get "401K Prospectus.pdf" }}
  {{ .RelPermalink }}                                 --> 401K Prospectus.pdf
{{ end }}
```

#### resources.GetMatch (FAIL)

```text
{{ with resources.GetMatch "401K Prospectus.pdf" }}
  {{ .RelPermalink }}                                 --> 401k-prospectus.pdf
{{ end }}
```

#### resources.Match (FAIL)

```text
{{ with resources.Match "401K Prospectus.pdf" }}
  {{ .RelPermalink }}                                 --> 401k-prospectus.pdf
{{ end }}
```

#### resources.ByType (FAIL)

```text
{{ range resources.ByType "application" }}
  {{ .RelPermalink }}                                 --> 401k-prospectus.pdf, etc.
{{ end }}
```

This does not happen with v0.122.0, nor does it affect the corresponding methods on Page.

Reference: <https://discourse.gohugo.io/t/hugo-v0-123-image-resources-being-converted-to-lowercase/48581/2>



Discussion / hints:

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 5388426c9a5..ddc22bb6652 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -1764,7 +1764,7 @@ func (sa *sitePagesAssembler) addStandalonePages() error {
 
 	if s.conf.EnableRobotsTXT {
 		if m.i == 0 || s.Conf.IsMultihost() {
-			addStandalone("/robots", kinds.KindRobotsTXT, output.RobotsTxtFormat)
+			addStandalone("/_robots", kinds.KindRobotsTXT, output.RobotsTxtFormat)
 		}
 	}
 
@@ -1777,11 +1777,11 @@ func (sa *sitePagesAssembler) addStandalonePages() error {
 	}
 
 	if sitemapEnabled {
-		addStandalone("/sitemap", kinds.KindSitemap, output.SitemapFormat)
+		addStandalone("/_sitemap", kinds.KindSitemap, output.SitemapFormat)
 		skipSitemapIndex := s.Conf.IsMultihost() || !(s.Conf.DefaultContentLanguageInSubdir() || s.Conf.IsMultiLingual())
 
 		if !skipSitemapIndex {
-			addStandalone("/sitemapindex", kinds.KindSitemapIndex, output.SitemapIndexFormat)
+			addStandalone("/_sitemapindex", kinds.KindSitemapIndex, output.SitemapIndexFormat)
 		}
 	}
 
diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go
index 0cf84c49b9c..ac1a2af0777 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


Test patch:
diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go
index 1f869c00063..6dad39fe339 100644
--- a/hugolib/sitemap_test.go
+++ b/hugolib/sitemap_test.go
@@ -148,3 +148,25 @@ Home.
 
 	b.AssertFileContent("public/sitemap.xml", "https://example.com/en/sitemap.xml")
 }
+
+func TestSitemapAndContentBundleNamedSitemap(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['home','rss','section','taxonomy','term']
+-- layouts/_default/single.html --
+layouts/_default/single.html
+-- layouts/sitemap/single.html --
+layouts/sitemap/single.html
+-- content/sitemap/index.md --
+---
+title: My sitemap
+type: sitemap
+---
+`
+
+	b := Test(t, files)
+
+	b.AssertFileExists("public/sitemap.xml", true)
+}
diff --git a/tpl/resources/resources_integration_test.go b/tpl/resources/resources_integration_test.go
index 5a3c296665a..d72b1350729 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|
+
+		`)
+}