fix(iflow): adjust auth filename email sanitization

This commit is contained in:
hkfires
2025-11-19 19:50:06 +08:00
parent 8a33f3ef69
commit b285b07986

View File

@@ -95,14 +95,13 @@ func promptForCookie(promptFn func(string) (string, error)) (string, error) {
// getAuthFilePath returns the auth file path for the given provider and email // getAuthFilePath returns the auth file path for the given provider and email
func getAuthFilePath(cfg *config.Config, provider, email string) string { func getAuthFilePath(cfg *config.Config, provider, email string) string {
// Clean email to make it filename-safe // Clean email to make it filename-safe
cleanEmail := strings.ReplaceAll(email, "@", "_at_") cleanEmail := strings.ReplaceAll(email, "*", "x")
cleanEmail = strings.ReplaceAll(cleanEmail, ".", "_")
cleanEmail = strings.ReplaceAll(cleanEmail, "-", "_")
// Remove any remaining special characters // Remove any unsafe characters, but allow standard email chars (@, ., -)
var result strings.Builder var result strings.Builder
for _, r := range cleanEmail { for _, r := range cleanEmail {
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' { if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') ||
r == '_' || r == '@' || r == '.' || r == '-' {
result.WriteRune(r) result.WriteRune(r)
} }
} }