Skip to content

Commit db85e83

Browse files
committed
resource: Make .Resources.GetByPrefix case insensitive
Fixes #4258
1 parent 1046e93 commit db85e83

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

‎resource/resource.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ func (r Resources) ByType(tp string) Resources {
7070
// "logo" will match logo.png. It returns nil of none found.
7171
// In potential ambiguous situations, combine it with ByType.
7272
func (r Resources) GetByPrefix(prefix string) Resource {
73+
prefix = strings.ToLower(prefix)
7374
for _, resource := range r {
7475
_, name := filepath.Split(resource.RelPermalink())
76+
name = strings.ToLower(name)
7577
if strings.HasPrefix(name, prefix) {
7678
return resource
7779
}

‎resource/resource_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ func TestResourcesGetByPrefix(t *testing.T) {
113113
resources := Resources{
114114
spec.newGenericResource(nil, nil, "/public", "/a/foo1.css", "foo1.css", "css"),
115115
spec.newGenericResource(nil, nil, "/public", "/a/logo1.png", "logo1.png", "image"),
116-
spec.newGenericResource(nil, nil, "/public", "/b/logo2.png", "logo2.png", "image"),
116+
spec.newGenericResource(nil, nil, "/public", "/b/Logo2.png", "Logo2.png", "image"),
117117
spec.newGenericResource(nil, nil, "/public", "/b/foo2.css", "foo2.css", "css"),
118118
spec.newGenericResource(nil, nil, "/public", "/b/foo3.css", "foo3.css", "css")}
119119

120120
assert.Nil(resources.GetByPrefix("asdf"))
121121
assert.Equal("/logo1.png", resources.GetByPrefix("logo").RelPermalink())
122+
assert.Equal("/logo1.png", resources.GetByPrefix("loGo").RelPermalink())
123+
assert.Equal("/Logo2.png", resources.GetByPrefix("logo2").RelPermalink())
122124
assert.Equal("/foo2.css", resources.GetByPrefix("foo2").RelPermalink())
123125
assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())
124126
assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())

0 commit comments

Comments
 (0)