修复初始化向导MySQL密码转换
Some checks are pending
Security Checks / security (push) Waiting to run

允许旧版 MySQL DSN 正确迁移包含 @ 的密码,并增加加密存储回归用例。
This commit is contained in:
smail 2026-09-29 22:45:07 +08:00
parent 55faa8e165
commit a28e3a3b72
2 changed files with 10 additions and 1 deletions

View File

@ -112,7 +112,7 @@ var legacyPluginExecutableMap = map[string]string{
"pmail_telegram_push.exe": "telegram_push",
}
var legacyMySQLDSNPattern = regexp.MustCompile(`^([^:@/[:space:]]+):([^@\r\n]*)@tcp\(([^():/[:space:]]+)(?::([0-9]{1,5}))?\)/([A-Za-z0-9][A-Za-z0-9._-]{0,127})(?:\?[^#[:space:]]*)?$`)
var legacyMySQLDSNPattern = regexp.MustCompile(`^([^:@/[:space:]]+):([^\r\n]*)@tcp\(([^():/[:space:]]+)(?::([0-9]{1,5}))?\)/([A-Za-z0-9][A-Za-z0-9._-]{0,127})(?:\?[^#[:space:]]*)?$`)
func PlanLegacyMigration(root string, _ RuntimeValidationOptions) (LegacyMigrationPlan, error) {
directory, err := secureManagerConfigDirectory(root)

View File

@ -631,6 +631,15 @@ func TestMigrateLegacyConfigParsesKnownStructuredDatabaseDSNs(t *testing.T) {
wantHost: "db.example.com",
wantName: "smail",
password: "database-secret",
}, {
name: "MySQL password with at sign",
database: DBTypeMySQL,
dsn: "smail:database@secret@tcp(db.example.com:3307)/smail?charset=utf8mb4",
wantType: DatabaseTypeMySQL,
wantPort: 3307,
wantHost: "db.example.com",
wantName: "smail",
password: "database@secret",
},
{
name: "PostgreSQL",