diff options
Diffstat (limited to 'modules/repository/generate.go')
-rw-r--r-- | modules/repository/generate.go | 6 |
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, "_")) } |