diff options
-rw-r--r-- | internal/source/gitlab/client/testdata/test.gitlab.io.json | 11 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab.go | 8 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab_test.go | 14 |
3 files changed, 30 insertions, 3 deletions
diff --git a/internal/source/gitlab/client/testdata/test.gitlab.io.json b/internal/source/gitlab/client/testdata/test.gitlab.io.json index c094e52a..086123a9 100644 --- a/internal/source/gitlab/client/testdata/test.gitlab.io.json +++ b/internal/source/gitlab/client/testdata/test.gitlab.io.json @@ -34,6 +34,17 @@ "type": "file", "sha256": "0f8ef3377b30fc47f96b48247f463a726a802f62f3faa03d56403751d2f66c67" } + }, + { + "access_control": false, + "https_only": true, + "prefix": "/my/capitalizedprefix/", + "project_id": 126, + "source": { + "path": "some/path/to/project/", + "type": "file", + "sha256": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3" + } } ] } diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index d3fbc8cc..40b127d2 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -73,16 +73,18 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.Request, error) { } urlPath := path.Clean(r.URL.Path) + lowerURLPath := strings.ToLower(urlPath) size := len(response.Domain.LookupPaths) for _, lookup := range response.Domain.LookupPaths { - isSubPath := strings.HasPrefix(urlPath, lookup.Prefix) - isRootPath := urlPath == path.Clean(lookup.Prefix) + lookupPrefix := strings.ToLower(lookup.Prefix) + isSubPath := strings.HasPrefix(lowerURLPath, lookupPrefix) + isRootPath := lowerURLPath == path.Clean(lookupPrefix) if isSubPath || isRootPath { subPath := "" if isSubPath { - subPath = strings.TrimPrefix(urlPath, lookup.Prefix) + subPath = urlPath[len(lookupPrefix):] } srv, err := g.fabricateServing(lookup) diff --git a/internal/source/gitlab/gitlab_test.go b/internal/source/gitlab/gitlab_test.go index 095fc2eb..6d5d978a 100644 --- a/internal/source/gitlab/gitlab_test.go +++ b/internal/source/gitlab/gitlab_test.go @@ -116,6 +116,20 @@ func TestResolve(t *testing.T) { expectedPath: "some/path/to/project/", expectedSubPath: "index.html", }, + "when project name requested is capitalized": { + file: "client/testdata/test.gitlab.io.json", + target: "https://test.gitlab.io:443/My/CapitalizedPrefix", + expectedPrefix: "/my/capitalizedprefix/", + expectedPath: "some/path/to/project/", + expectedSubPath: "", + }, + "when project name and requested path are capitalized": { + file: "client/testdata/test.gitlab.io.json", + target: "https://test.gitlab.io:443/My/CapitalizedPrefix/Path/Index.html", + expectedPrefix: "/my/capitalizedprefix/", + expectedPath: "some/path/to/project/", + expectedSubPath: "Path/Index.html", + }, } for name, tc := range tests { |