summaryrefslogtreecommitdiffstats
path: root/resource
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-11 18:58:53 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-11 18:58:53 +0100
commitdb85e83403913cff4b8737b138932b28e5bf6160 (patch)
tree9c1e231dccbac72acbcdf1ec957636ae6789bc97 /resource
parent1046e9363f2e382fd0b4aac838735ae4cbbebe5a (diff)
resource: Make .Resources.GetByPrefix case insensitive
Fixes #4258
Diffstat (limited to 'resource')
-rw-r--r--resource/resource.go2
-rw-r--r--resource/resource_test.go4
2 files changed, 5 insertions, 1 deletions
diff --git a/resource/resource.go b/resource/resource.go
index c668a0efe..9cf9524b8 100644
--- a/resource/resource.go
+++ b/resource/resource.go
@@ -70,8 +70,10 @@ func (r Resources) ByType(tp string) Resources {
// "logo" will match logo.png. It returns nil of none found.
// In potential ambiguous situations, combine it with ByType.
func (r Resources) GetByPrefix(prefix string) Resource {
+ prefix = strings.ToLower(prefix)
for _, resource := range r {
_, name := filepath.Split(resource.RelPermalink())
+ name = strings.ToLower(name)
if strings.HasPrefix(name, prefix) {
return resource
}
diff --git a/resource/resource_test.go b/resource/resource_test.go
index 847c26843..fbc66af8f 100644
--- a/resource/resource_test.go
+++ b/resource/resource_test.go
@@ -113,12 +113,14 @@ func TestResourcesGetByPrefix(t *testing.T) {
resources := Resources{
spec.newGenericResource(nil, nil, "/public", "/a/foo1.css", "foo1.css", "css"),
spec.newGenericResource(nil, nil, "/public", "/a/logo1.png", "logo1.png", "image"),
- spec.newGenericResource(nil, nil, "/public", "/b/logo2.png", "logo2.png", "image"),
+ spec.newGenericResource(nil, nil, "/public", "/b/Logo2.png", "Logo2.png", "image"),
spec.newGenericResource(nil, nil, "/public", "/b/foo2.css", "foo2.css", "css"),
spec.newGenericResource(nil, nil, "/public", "/b/foo3.css", "foo3.css", "css")}
assert.Nil(resources.GetByPrefix("asdf"))
assert.Equal("/logo1.png", resources.GetByPrefix("logo").RelPermalink())
+ assert.Equal("/logo1.png", resources.GetByPrefix("loGo").RelPermalink())
+ assert.Equal("/Logo2.png", resources.GetByPrefix("logo2").RelPermalink())
assert.Equal("/foo2.css", resources.GetByPrefix("foo2").RelPermalink())
assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())
assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())