summaryrefslogtreecommitdiffstats
path: root/modules/repository/generate.go
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2023-06-21 14:57:18 -0500
committerGitHub <noreply@github.com>2023-06-21 19:57:18 +0000
commit8afc1b1cb5ad44ab5dd9597a814b19412702ede3 (patch)
tree474dacac5cfe4ab90bbd51c43973ff54e2caa674 /modules/repository/generate.go
parent25455bc670910111d8cbb5293f95713416d22a0e (diff)
downloadgitea-8afc1b1cb5ad44ab5dd9597a814b19412702ede3.tar.gz
gitea-8afc1b1cb5ad44ab5dd9597a814b19412702ede3.zip
Move some regexp out of functions (#25430)
/cc @KN4CK3R https://github.com/go-gitea/gitea/pull/25294#discussion_r1237425343 I also searched the codebase and found a few more. --------- Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'modules/repository/generate.go')
-rw-r--r--modules/repository/generate.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index 102c5af1c9..cb25daa10b 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -372,12 +372,12 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
return generateRepo, nil
}
+var fileNameSanitizeRegexp = regexp.MustCompile(`(?i)\.\.|[<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
+
// Sanitize user input to valid OS filenames
//
// Based on https://github.com/sindresorhus/filename-reserved-regex
// Adds ".." to prevent directory traversal
func fileNameSanitize(s string) string {
- re := regexp.MustCompile(`(?i)\.\.|[<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
-
- return strings.TrimSpace(re.ReplaceAllString(s, "_"))
+ return strings.TrimSpace(fileNameSanitizeRegexp.ReplaceAllString(s, "_"))
}