From 49d6079f9ac4e30a15aba4df45d1c42bb64711db Mon Sep 17 00:00:00 2001 From: pyama Date: Tue, 26 Dec 2023 17:18:29 +0900 Subject: [PATCH] fix null pattern --- base_limiter.go | 2 +- base_limiter_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/base_limiter.go b/base_limiter.go index 9c4a979..390b496 100644 --- a/base_limiter.go +++ b/base_limiter.go @@ -34,7 +34,7 @@ func NewBaseLimiter( targetExtensionsMap := make(map[string]struct{}, len(targetExtensions)) if len(targetExtensions) > 0 { for _, ext := range targetExtensions { - if ext[0] != '.' { + if len(ext) > 0 && ext[0] != '.' { ext = "." + ext } targetExtensionsMap[strings.ToLower(ext)] = struct{}{} diff --git a/base_limiter_test.go b/base_limiter_test.go index 198fec6..e0e2a9f 100644 --- a/base_limiter_test.go +++ b/base_limiter_test.go @@ -54,6 +54,12 @@ func TestBaseLimiter_isTargetExtensions(t *testing.T) { requestPath: "/file", want: false, }, + { + name: "null extention", + targetExtensions: []string{""}, + requestPath: "/file", + want: true, + }, } for _, tt := range tests {