Repository navigation
MySQL and ClickHouse database names in Docker Compose JDBC URLs are not URL encoded - #52817
Merged
philwebb merged 2 commits intoNov 19, 2026
Conversation
There was a problem hiding this comment.
🟢 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
%20for 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
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
force-pushed
the
mysql-clickhouse-database-url-encoding
branch
from
November 19, 2026 18:13
a43094e to
5492a2b
Compare
Member
|
Thanks @eatmoreduck! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:my?dbmy(truncated, rest becomes query params)my(truncated)my%dbmy\ufffd(%dbpercent-decoded to an invalid sequence)my\ufffdmy dbmy dbInvalid 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%20rather than the x-www-form-urlencoded+. The MySQL driver decodes both%XXand+, so plainURLEncoder.encoderound-trips there (verified withConnectionUrl.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%20for spaces.mysql-connector-jmoved fromtestRuntimeOnlytotestImplementationso the first test can use the driver's URL parsing API.