Skip to content

MySQL and ClickHouse database names in Docker Compose JDBC URLs are not URL encoded - #52817

Merged
philwebb merged 2 commits into
spring-projects:4.0.xfrom
eatmoreduck:mysql-clickhouse-database-url-encoding
Nov 19, 2026
Merged

philwebb merged 2 commits into
spring-projects:4.0.xfrom
eatmoreduck:mysql-clickhouse-database-url-encoding

Conversation

@eatmoreduck

Copy link
Copy Markdown
Contributor

Description

Follow-up to #52625, which URL-encoded the database name for PostgreSQL Docker Compose services. The MySQL and ClickHouse factories append the database name to the JDBC URL without encoding, so a name containing ?, %, or other URL-significant characters is parsed incorrectly by the driver:

Database name MySQL URL (Connector/J 9.4) ClickHouse URL (0.8.5)
my?db parsed database: my (truncated, rest becomes query params) parsed database: my (truncated)
my%db parsed database: my\ufffd (%db percent-decoded to an invalid sequence) parsed database: my\ufffd
my db parsed database: my db driver rejects the URL (Invalid URI)

The fix encodes the database name the same way as the PostgreSQL support, with one driver-specific difference: the ClickHouse driver percent-decodes the database segment but leaves a literal + untouched, so spaces are encoded as %20 rather than the x-www-form-urlencoded +. The MySQL driver decodes both %XX and +, so plain URLEncoder.encode round-trips there (verified with ConnectionUrl.getConnectionUrlInstance(...).getDatabase()).

MariaDB is deliberately left unchanged: its driver (3.5.x) does not percent-decode the database segment, so encoding the name would produce a URL that connects to a database with the encoded (wrong) name. That case would need driver-side support first.

Test coverage

  • MySqlJdbcDockerComposeConnectionDetailsFactoryConnectionDetailsTests (new) asserts, for a parameterized set of names (my+db, my?db, my/db, my%db, my db, my数据库), that Connector/J parses the generated URL back to the exact database name.
  • ClickHouseJdbcDockerComposeConnectionDetailsFactoryConnectionDetailsTests (new) asserts the generated URL ends with the percent-encoded name, including %20 for spaces.
  • mysql-connector-j moved from testRuntimeOnly to testImplementation so the first test can use the driver's URL parsing API.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:05
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Nov 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the MySQL and ClickHouse JDBC database-name encoding changes.

No open issues 🎉

What changed in this PR

Extends the PostgreSQL fix from #52625 to Spring Boot’s MySQL and ClickHouse Docker Compose JDBC support, preserving database names containing URL-significant characters.

Changes:

  • Encodes database names before building JDBC URLs, using %20 for spaces in ClickHouse.
  • Adds MySQL driver round-trip tests and ClickHouse encoded-URL assertions.
  • Makes Connector/J available at test compile time; leaves MariaDB unchanged.
File Description
module/​spring-boot-jdbc/​src/​test/​java/​org/​springframework/​boot/​jdbc/​docker/​compose/​MySqlJdbcDockerComposeConnectionDetailsFactoryConnectionDetailsTests.java Tests database-name round trips through Connector/J and connection parameters.
module/​spring-boot-jdbc/​src/​test/​java/​org/​springframework/​boot/​jdbc/​docker/​compose/​ClickHouseJdbcDockerComposeConnectionDetailsFactoryConnectionDetailsTests.java Tests encoded database names and connection parameters.
module/​spring-boot-jdbc/​src/​main/​java/​org/​springframework/​boot/​jdbc/​docker/​compose/​MySqlJdbcDockerComposeConnectionDetailsFactory.java URL-encodes database names using UTF-8.
module/​spring-boot-jdbc/​src/​main/​java/​org/​springframework/​boot/​jdbc/​docker/​compose/​ClickHouseJdbcDockerComposeConnectionDetailsFactory.java Percent-encodes database names, including spaces as %20.
module/​spring-boot-jdbc/​build.gradle Moves Connector/J to testImplementation for parser-based tests.

Review effort: Balanced

@philwebb philwebb changed the title URL-encode database names in MySQL and ClickHouse Docker Compose JDBC URLs MySQL and ClickHouse database names in Docker Compose JDBC URLs are not URL encoded Nov 16, 2026
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Nov 16, 2026
@philwebb philwebb added this to the 4.0.x milestone Nov 16, 2026
@philwebb philwebb self-assigned this Nov 19, 2026
eatmoreduck and others added 2 commits November 19, 2026 10:11
A MySQL or ClickHouse service's database name is appended to the JDBC URL
without encoding. A name containing '?', '%' or other URL-significant
characters is then truncated or mis-decoded by the driver. Encode it the
same way as the PostgreSQL support added in spring-projects#52625, with one difference:
the ClickHouse driver leaves a literal '+' untouched, so spaces are
encoded as %20 rather than the x-www-form-urlencoded '+'.

MariaDB is deliberately left unchanged: its driver does not percent-decode
the database segment so encoding would cause a connection to a database
with the wrong name.

See spring-projectsgh-52817

Signed-off-by: yu.xia <[email protected]>
Push encoding logic into `JdbcUrlBuilder`.

See spring-projectsgh-52817
@philwebb
philwebb force-pushed the mysql-clickhouse-database-url-encoding branch from a43094e to 5492a2b Compare November 19, 2026 18:13
@philwebb
philwebb changed the base branch from main to 4.0.x November 19, 2026 18:14
@philwebb
philwebb merged commit 61fb90d into spring-projects:4.0.x Nov 19, 2026
3 of 4 checks passed
@philwebb philwebb modified the milestones: 4.0.x, 4.0.11 Nov 19, 2026
@philwebb

Copy link
Copy Markdown
Member

Thanks @eatmoreduck!

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

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants