Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <376774-nolith@users.noreply.gitlab.com>2024-01-24 11:16:38 +0300
committerAlessio Caiazza <376774-nolith@users.noreply.gitlab.com>2024-01-24 11:16:38 +0300
commitd8501186fd12f2d17ee48fa27a63488f58b0d0be (patch)
tree6e779bb604a017c51189b57b15916c8d08f0d185
parentbc122e0c78e1bd4862aceb99162f8ec327fb91d6 (diff)
parent0f5850946704c461f4415c5d1cfc5ce9c89b1644 (diff)
Merge branch 'kassio/fix-pages-be-case-insensitive-on-project-paths' into 'master'HEADmaster
Fix project path lookup to work in case insensitive See merge request https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/948 Merged-by: Alessio Caiazza <376774-nolith@users.noreply.gitlab.com> Approved-by: Alessio Caiazza <376774-nolith@users.noreply.gitlab.com> Approved-by: Naman Jagdish Gala <ngala@gitlab.com> Reviewed-by: Naman Jagdish Gala <ngala@gitlab.com> Co-authored-by: Kassio Borges <kassioborgesm@gmail.com>
-rw-r--r--internal/source/gitlab/client/testdata/test.gitlab.io.json11
-rw-r--r--internal/source/gitlab/gitlab.go8
-rw-r--r--internal/source/gitlab/gitlab_test.go14
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 {