Skip to content

fix(gdb/mysql): always URL-encode timezone value in DSN to prevent '+' from being interpreted as space (#4759) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #4822

Open
waterWang wants to merge 1 commit into
gogf:masterfrom
waterWang:fix/mysql-dsn-timezone-encoding

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

fix #4759

Problem

When setting a MySQL timezone value containing '+' (e.g., '+00:00'), the configNodeToSource function only URL-encodes the timezone if it contains '/'. The '+' character is not encoded, causing the Go MySQL driver to interpret it as a space in the query string, resulting in:

unknown time zone ' 00:00'

Fix

Always URL-encode the timezone value with url.QueryEscape instead of only when it contains '/'. This ensures special characters like '+', ':', and quotes are correctly encoded.

- if strings.Contains(config.Timezone, "/") {
-     config.Timezone = url.QueryEscape(config.Timezone)
- }
+ config.Timezone = url.QueryEscape(config.Timezone)

Verification

  • url.QueryEscape(UTC)UTC (no change for safe values)
  • url.QueryEscape(Asia/Shanghai)Asia%2FShanghai (same as before)
  • url.QueryEscape(+00:00)%27%2B00%3A00%27 (now correctly encoded)
  • The strings import is no longer needed and has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gdb: set session variables time_zone cause error

1 participant