From a28e3a3b72efb4e638f10e3d168573a618d3bea5 Mon Sep 17 00:00:00 2001 From: smail Date: Tue, 29 Sep 2026 22:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=90=91=E5=AF=BCMySQL=E5=AF=86=E7=A0=81=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 允许旧版 MySQL DSN 正确迁移包含 @ 的密码,并增加加密存储回归用例。 --- backend/config/migrate.go | 2 +- backend/config/migrate_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/config/migrate.go b/backend/config/migrate.go index 2e59159..012d14c 100644 --- a/backend/config/migrate.go +++ b/backend/config/migrate.go @@ -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) diff --git a/backend/config/migrate_test.go b/backend/config/migrate_test.go index 709e9b6..ec14e8c 100644 --- a/backend/config/migrate_test.go +++ b/backend/config/migrate_test.go @@ -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",