Skip to content

Commit 75ffae4

Browse files
committed
Substitute paths in repo templates
1 parent 6db66d8 commit 75ffae4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

modules/repository/generate.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path"
1313
"path/filepath"
14+
"regexp"
1415
"strings"
1516
"time"
1617

@@ -195,6 +196,14 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
195196
0o644); err != nil {
196197
return err
197198
}
199+
200+
// Substitute filename variables
201+
if err := os.Rename(path,
202+
filepath.FromSlash(filepath.Join(tmpDirSlash,
203+
fileNameEscape(generateExpansion(base, templateRepo, generateRepo))))); err != nil {
204+
return err
205+
}
206+
198207
break
199208
}
200209
}
@@ -353,3 +362,12 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
353362

354363
return generateRepo, nil
355364
}
365+
366+
// Escapes user input to valid OS filenames
367+
//
368+
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
369+
func fileNameEscape(s string) string {
370+
re := regexp.MustCompile("[/<>:\"\\|?*\n]")
371+
372+
return re.ReplaceAllString(s, "*")
373+
}

0 commit comments

Comments
 (0)