Repository: gohugoio/hugo (language: go)

Issue:
resources.Get and resources.GetMatch failing when used with resources.ByType and resources.Match
Worked (sort of) in v0.123.7. Fails in v0.123.8.

Related to <https://github.com/gohugoio/hugo/issues/12190>, but global assets are in subdirectory.

```content
assets/
└── snippets/
    ├── a.txt
    └── b.txt
```

```text
{{ range resources.ByType "text" }}
  {{ .Name }}
{{ end }}
```

Expected (v0.123.7) --> `/snippets/a.txt`  (note that in v0.122.0 this returned `snippets/a.txt` -- no leading slash)

Actual (v0.123.8) --> `a.txt`

I believe the above is causing both of these to fail (resources are not published):

```text
{{ with resources.ByType "text" }}
  {{ with .Get "snippets/a.txt" }}
    {{ .Publish }}
  {{ end }}
{{ end }}

{{ with resources.Match "**" }}
  {{ with .GetMatch "snippets/b.txt" }}
    {{ .Publish }}
  {{ end }}
{{ end }}
```




Discussion / hints:

Fix patch:
diff --git a/resources/resource/resources.go b/resources/resource/resources.go
index aa01d4ce27d..32bcdbb088a 100644
--- a/resources/resource/resources.go
+++ b/resources/resource/resources.go
@@ -18,6 +18,7 @@ import (
 	"fmt"
 	"strings"
 
+	"github.com/gohugoio/hugo/common/paths"
 	"github.com/gohugoio/hugo/hugofs/glob"
 	"github.com/spf13/cast"
 )
@@ -61,13 +62,14 @@ func (r Resources) Get(name any) Resource {
 	if err != nil {
 		panic(err)
 	}
-	namestr = strings.ToLower(namestr)
+
+	namestr = paths.AddLeadingSlash(namestr)
 
 	// First check the Name.
 	// Note that this can be modified by the user in the front matter,
 	// also, it does not contain any language code.
 	for _, resource := range r {
-		if strings.EqualFold(namestr, resource.Name()) {
+		if strings.EqualFold(namestr, paths.AddLeadingSlash(resource.Name())) {
 			return resource
 		}
 	}
@@ -75,7 +77,7 @@ func (r Resources) Get(name any) Resource {
 	// Finally, check the normalized name.
 	for _, resource := range r {
 		if nop, ok := resource.(NameNormalizedProvider); ok {
-			if strings.EqualFold(namestr, nop.NameNormalized()) {
+			if strings.EqualFold(namestr, paths.AddLeadingSlash(nop.NameNormalized())) {
 				return resource
 			}
 		}
@@ -92,21 +94,21 @@ func (r Resources) GetMatch(pattern any) Resource {
 		panic(err)
 	}
 
-	g, err := glob.GetGlob(patternstr)
+	g, err := glob.GetGlob(paths.AddLeadingSlash(patternstr))
 	if err != nil {
 		panic(err)
 	}
 
 	for _, resource := range r {
-		if g.Match(resource.Name()) {
+		if g.Match(paths.AddLeadingSlash(resource.Name())) {
 			return resource
 		}
 	}
 
-	// Finally, check the original name.
+	// Finally, check the normalized name.
 	for _, resource := range r {
 		if nop, ok := resource.(NameNormalizedProvider); ok {
-			if g.Match(nop.NameNormalized()) {
+			if g.Match(paths.AddLeadingSlash(nop.NameNormalized())) {
 				return resource
 			}
 		}
@@ -130,14 +132,14 @@ func (r Resources) Match(pattern any) Resources {
 		panic(err)
 	}
 
-	g, err := glob.GetGlob(patternstr)
+	g, err := glob.GetGlob(paths.AddLeadingSlash(patternstr))
 	if err != nil {
 		panic(err)
 	}
 
 	var matches Resources
 	for _, resource := range r {
-		if g.Match(resource.Name()) {
+		if g.Match(paths.AddLeadingSlash(resource.Name())) {
 			matches = append(matches, resource)
 		}
 	}
@@ -145,7 +147,7 @@ func (r Resources) Match(pattern any) Resources {
 		// 	Fall back to the normalized name.
 		for _, resource := range r {
 			if nop, ok := resource.(NameNormalizedProvider); ok {
-				if g.Match(nop.NameNormalized()) {
+				if g.Match(paths.AddLeadingSlash(nop.NameNormalized())) {
 					matches = append(matches, resource)
 				}
 			}
diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go
index 1ecc4652d03..061ecf1e7f0 100644
--- a/resources/resource_factories/create/create.go
+++ b/resources/resource_factories/create/create.go
@@ -134,8 +134,8 @@ func (c *Client) match(name, pattern string, matchFunc func(r resource.Resource)
 				OpenReadSeekCloser: func() (hugio.ReadSeekCloser, error) {
 					return meta.Open()
 				},
-				NameNormalized: meta.PathInfo.Name(),
-				NameOriginal:   meta.PathInfo.Unnormalized().Name(),
+				NameNormalized: meta.PathInfo.Path(),
+				NameOriginal:   meta.PathInfo.Unnormalized().Path(),
 				GroupIdentity:  meta.PathInfo,
 				TargetPath:     meta.PathInfo.Unnormalized().Path(),
 			})


Test patch:
diff --git a/hugolib/mount_filters_test.go b/hugolib/mount_filters_test.go
index eec2e713d2d..16b062ec6cc 100644
--- a/hugolib/mount_filters_test.go
+++ b/hugolib/mount_filters_test.go
@@ -112,6 +112,6 @@ Template: false
 Resource1: /js/include.js:END
 Resource2: :END
 Resource3: :END
-Resources: [include.js]
+Resources: [/js/include.js]
 `)
 }
diff --git a/tpl/resources/resources_integration_test.go b/tpl/resources/resources_integration_test.go
index b4630b6a237..6bc872bca8e 100644
--- a/tpl/resources/resources_integration_test.go
+++ b/tpl/resources/resources_integration_test.go
@@ -171,3 +171,70 @@ Home.
 	b.AssertFileExists("public/a.txt", true) // failing test
 	b.AssertFileExists("public/b.txt", true) // failing test
 }
+
+func TestGlobalResourcesNotPublishedRegressionIssue12214(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+-- assets/files/a.txt --
+I am a.txt
+-- assets/files/b.txt --
+I am b.txt
+-- assets/files/c.txt --
+I am c.txt
+-- assets/files/C.txt --
+I am C.txt
+-- layouts/index.html --
+Home.
+{{ with resources.ByType "text" }}
+  {{ with .Get "files/a.txt" }}
+    {{ .Publish }}
+	files/a.txt: {{ .Name }}
+  {{ end }}
+  {{ with .Get "/files/a.txt" }}
+	/files/a.txt: {{ .Name }}
+  {{ end }}
+  {{ with .GetMatch "files/*b*" }}
+    {{ .Publish }}
+	files/*b*: {{ .Name }}
+  {{ end }}
+  {{ with .GetMatch "files/C*" }}
+    {{ .Publish }}
+    files/C*: {{ .Name }}
+  {{ end }}
+  {{ with .GetMatch "files/c*" }}
+	{{ .Publish }}
+	files/c*: {{ .Name }}
+  {{ end }}
+  {{ with .GetMatch "/files/c*" }}
+    /files/c*: {{ .Name }}
+  {{ end }}
+  {{ with .Match "files/C*" }}
+	match files/C*: {{ len . }}|
+  {{ end }}
+  {{ with .Match "/files/C*" }}
+  match /files/C*: {{ len . }}|
+{{ end }}
+{{ end }}
+`
+
+	b := hugolib.Test(t, files)
+
+	b.AssertFileContent("public/index.html", `
+files/a.txt: /files/a.txt
+# There are both C.txt and c.txt in the assets, but the Glob matching is case insensitive, so GetMatch returns the first.
+files/C*: /files/C.txt
+files/c*: /files/C.txt
+files/*b*: /files/b.txt
+/files/c*: /files/C.txt
+/files/a.txt: /files/a.txt
+match files/C*: 2|
+match /files/C*: 2|
+	`)
+
+	b.AssertFileContent("public/files/a.txt", "I am a.txt")
+	b.AssertFileContent("public/files/b.txt", "I am b.txt")
+	b.AssertFileContent("public/files/C.txt", "I am C.txt")
+}