Skip to content

Commit fd47c3b

Browse files
committed
fine tune
1 parent b4ab320 commit fd47c3b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

services/lfs/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func GetLFSAuthTokenWithBearer(opts AuthTokenOptions) (string, error) {
7777
// Sign and get the complete encoded token as a string using the secret
7878
tokenString, err := token.SignedString(setting.LFS.JWTSecretBytes)
7979
if err != nil {
80-
return "", fmt.Errorf("failed to sign token: %w", err)
80+
return "", fmt.Errorf("failed to sign LFS JWT token: %w", err)
8181
}
8282
return "Bearer " + tokenString, nil
8383
}

services/repository/generate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ var globalVars = sync.OnceValue(func() (ret struct {
5555
{Name: "UPPER", Transform: strings.ToUpper},
5656
{Name: "TITLE", Transform: util.ToTitleCase},
5757
}
58+
59+
// invalid filename contents, based on https://github.com/sindresorhus/filename-reserved-regex
60+
// "COM10" needs to be opened with UNC "\\.\COM10" on Windows, so itself is valid
5861
ret.fileNameSanitizeRegexp = regexp.MustCompile(`(?i)[<>:"/\\|?*\x{0000}-\x{001F}]|^(con|prn|aux|nul|com\d|lpt\d)$`)
5962
return ret
6063
})
@@ -336,7 +339,6 @@ func (gro GenerateRepoOptions) IsValid() bool {
336339
gro.IssueLabels || gro.ProtectedBranch // or other items as they are added
337340
}
338341

339-
// Sanitize user input to valid OS filenames, based on https://github.com/sindresorhus/filename-reserved-regex
340342
func filePathSanitize(s string) string {
341343
fields := strings.Split(filepath.ToSlash(s), "/")
342344
for i, field := range fields {

services/repository/generate_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func TestFilePathSanitize(t *testing.T) {
6262
assert.Equal(t, "_", filePathSanitize("CoM1"))
6363
assert.Equal(t, "_", filePathSanitize("\u0000"))
6464
assert.Equal(t, "目标", filePathSanitize("目标"))
65-
assert.Equal(t, "目标", filePathSanitize("目标"))
65+
// unlike filepath.Clean, it only sanitizes, doesn't change the separator layout
66+
assert.Equal(t, "", filePathSanitize(""))
67+
assert.Equal(t, ".", filePathSanitize("."))
68+
assert.Equal(t, "/", filePathSanitize("/"))
6669
}
6770

6871
func TestProcessGiteaTemplateFile(t *testing.T) {

0 commit comments

Comments
 (0)