Skip to content

PostgreSQL database names in Docker Compose JDBC URLs are not URL encoded - #52625

Merged
philwebb merged 2 commits into
spring-projects:4.0.xfrom
raunakpandey1:fix/postgres-docker-compose-database-encoding
Nov 12, 2026
Merged

philwebb merged 2 commits into
spring-projects:4.0.xfrom
raunakpandey1:fix/postgres-docker-compose-database-encoding

Conversation

@raunakpandey1

@raunakpandey1 raunakpandey1 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

A PostgreSQL Docker Compose service with POSTGRES_DB=my+database currently gets a JDBC URL ending in /my+database. pgJDBC URL-decodes the database name, so it reads this as my database. Names containing ?, /, or literal percent escapes can likewise select a different name, alter the query parameters, or produce an invalid URL.

For example, this service triggers the affected connection-details path when using Spring Boot's Docker Compose JDBC support:

services:
  postgres:
    image: postgres:17
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: my+database
    ports:
      - "5432"

Encode the database name with the existing UTF-8 URL encoder before constructing the PostgreSQL JDBC URL. The example then uses /my%2Bdatabase, which pgJDBC reads as the original my+database. This follows pgJDBC's connection URL requirements and leaves the shared JDBC URL builder unchanged.

The regression test passes generated connection URLs through pgJDBC's actual Driver.parseURL, covering reserved characters, literal percent escapes, spaces, and Unicode, while also checking that the explicit connection parameters and automatic application name survive.

Validation on current main (c1eb7d54a7149da16bc5d632d7464dba3b11b88e, 4.2.0-SNAPSHOT), Temurin JDK 25.0.5, pgJDBC 42.7.14:

  • Before the fix: five failures in the 13-test PostgreSQL connection-details suite.
  • After the fix: all 460 JDBC unit tests passed, with no skips.
  • :module:spring-boot-jdbc:checkFormat, checkstyleMain, and checkstyleTest passed; git diff --check passed.
  • Docker integration tests and the full repository test suite were not run. URL parsing was verified without a database connection.

@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 5, 2026
@philwebb philwebb self-assigned this Nov 12, 2026
@philwebb philwebb changed the title Encode PostgreSQL database names in Docker Compose JDBC URLs PostgreSQL database names in Docker Compose JDBC URLs are not URL encoded Nov 12, 2026
@philwebb philwebb added type: bug A general bug for: merge-with-amendments Needs some changes when we merge and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Nov 12, 2026
@philwebb philwebb added this to the 4.0.x milestone Nov 12, 2026
raunakpandey1 and others added 2 commits November 12, 2026 14:22
Update `PostgresJdbcDockerComposeConnectionDetailsFactory` to URL
encode PostgreSQL database names.

See spring-projectsgh-52625

Signed-off-by: Raunak <raunakpandey1007@gmail.com>
@philwebb
philwebb force-pushed the fix/postgres-docker-compose-database-encoding branch from 66f2289 to da224e3 Compare November 12, 2026 22:25
@philwebb philwebb removed the for: merge-with-amendments Needs some changes when we merge label Nov 12, 2026
@philwebb
philwebb changed the base branch from main to 4.0.x November 12, 2026 22:26
@philwebb philwebb modified the milestones: 4.0.x, 4.0.10 Nov 12, 2026
@philwebb

Copy link
Copy Markdown
Member

Thanks @raunakpandey1!

@philwebb
philwebb merged commit a938bea into spring-projects:4.0.x Nov 12, 2026
3 of 4 checks passed
@raunakpandey1

Copy link
Copy Markdown
Contributor Author

Glad to contribute to my favourite framework @philwebb :)

philwebb pushed a commit to eatmoreduck/spring-boot that referenced this pull request Nov 19, 2026
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 <yuxianice@163.com>
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.

3 participants