Skip to content

Commit 7afe120

Browse files
committed
Add . to filename escape
1 parent 580fc92 commit 7afe120

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

modules/repository/generate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,10 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
365365

366366
// Escapes user input to valid OS filenames
367367
//
368-
// https://github.com/sindresorhus/filename-reserved-regex
368+
// Based on https://github.com/sindresorhus/filename-reserved-regex
369+
// Adds "." to prevend directory traversal
369370
func fileNameEscape(s string) string {
370-
re := regexp.MustCompile(`(?i)[<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
371+
re := regexp.MustCompile(`(?i)[\.<>:\"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
371372

372373
return re.ReplaceAllString(s, "_")
373374
}

modules/repository/generate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestGiteaTemplate(t *testing.T) {
5757

5858
func TestFileNameEscape(t *testing.T) {
5959
assert.Equal(t, "test_CON", fileNameEscape("test_CON"))
60-
assert.Equal(t, "http___localhost_3003_user_test.git", fileNameEscape("http://localhost:3003/user/test.git"))
60+
assert.Equal(t, "http___localhost_3003_user_test_git", fileNameEscape("http://localhost:3003/user/test.git"))
6161
assert.Equal(t, "_", fileNameEscape("CON"))
6262
assert.Equal(t, "_", fileNameEscape("con"))
6363
assert.Equal(t, "_", fileNameEscape("\u0000"))

0 commit comments

Comments
 (0)