]> source.dussan.org Git - gitea.git/commitdiff
Fix redirect when using lowercase reponame (#18775) (#18902)
authorOtto Richter (fnetX) <git@fralix.ovh>
Sat, 26 Feb 2022 00:16:22 +0000 (01:16 +0100)
committerGitHub <noreply@github.com>
Sat, 26 Feb 2022 00:16:22 +0000 (08:16 +0800)
* Previously,  `GET {username}/{reponame}/raw///file-path` (the middle two slashes are blank to get the default branch) when the repo name has uppercase letters, e.g., https://try.gitea.io/AbdulrhmnGhanem/CH330_Hardware, using a lowercase version of the name redirected to the correct URL
* In other words both
   * `GET https://try.gitea.io/AbdulrhmnGhanem/CH330_Hardware/raw///images/back.png`
   * `GET https://try.gitea.io/AbdulrhmnGhanem/ch330_hardware/raw///images/back.png`
were redirecting to ` GET https://try.gitea.io/AbdulrhmnGhanem/CH330_Hardware/raw/branch/master/images/back.png`
This isn't the case after  #17551. Specifically because of this [line](https://github.com/zeripath/gitea/blob/cbd5eecd148dfca5fcb1a3da469e491a84f6b32b/modules/context/repo.go#L860).

Co-authored-by: Ghanem <37152329+AbdulrhmnGhanem@users.noreply.github.com>
modules/context/repo.go

index bf782383b59c30bfa556e9c2c997f700f1226342..fb7d98583a8e1ab939384f92eb7b1525b8308938 100644 (file)
@@ -911,7 +911,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
 
                        if refType == RepoRefLegacy {
                                // redirect from old URL scheme to new URL scheme
-                               prefix := strings.TrimPrefix(setting.AppSubURL+strings.TrimSuffix(ctx.Req.URL.Path, ctx.Params("*")), ctx.Repo.RepoLink)
+                               prefix := strings.TrimPrefix(setting.AppSubURL+strings.ToLower(strings.TrimSuffix(ctx.Req.URL.Path, ctx.Params("*"))), strings.ToLower(ctx.Repo.RepoLink))
 
                                ctx.Redirect(path.Join(
                                        ctx.Repo.RepoLink,