aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2023-06-22 11:01:54 -0500
committerGitHub <noreply@github.com>2023-06-22 16:01:54 +0000
commit734fd93f59370846aa957ca57a054329d7d936dd (patch)
tree8be18f0360b1049f8ae6815308f8cd8353695ab1 /modules
parent203fe2841dd13bcccf5f526de0c07313f7a24dc1 (diff)
downloadgitea-734fd93f59370846aa957ca57a054329d7d936dd.tar.gz
gitea-734fd93f59370846aa957ca57a054329d7d936dd.zip
Move some regexp out of functions (#25430) (#25445)
Partial backport of #25430 Not a bug, but worth backporting for efficiency. Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/util/path.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/modules/util/path.go b/modules/util/path.go
index 1a68bc7488..58258560dd 100644
--- a/modules/util/path.go
+++ b/modules/util/path.go
@@ -222,6 +222,8 @@ func isOSWindows() bool {
return runtime.GOOS == "windows"
}
+var driveLetterRegexp = regexp.MustCompile("/[A-Za-z]:/")
+
// FileURLToPath extracts the path information from a file://... url.
func FileURLToPath(u *url.URL) (string, error) {
if u.Scheme != "file" {
@@ -235,8 +237,7 @@ func FileURLToPath(u *url.URL) (string, error) {
}
// If it looks like there's a Windows drive letter at the beginning, strip off the leading slash.
- re := regexp.MustCompile("/[A-Za-z]:/")
- if re.MatchString(path) {
+ if driveLetterRegexp.MatchString(path) {
return path[1:], nil
}
return path, nil