testcontainers / testcontainers/testcontainers-java
[Bug]: `ScriptUtils` converts adjacent string literals to invalid syntax
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Module
PostgreSQL
Testcontainers version
2.0.1
Using the latest Testcontainers version?
Yes
Host OS
macOS
Host Arch
arm64
Docker version
Client:
Version: 28.5.1
API version: 1.51
Go version: go1.24.8
Git commit: e180ab8
Built: Wed Oct 8 12:16:17 2025
OS/Arch: darwin/arm64
Context: desktop-linux
Server: Docker Desktop 4.49.0 (208700)
Engine:
Version: 28.5.1
API version: 1.51 (minimum version 1.24)
Go version: go1.24.8
Git commit: f8215cc
Built: Wed Oct 8 12:18:25 2025
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.7.27
GitCommit: 05044ec0a9a75232cad458027ca83437aae3f4da
runc:
Version: 1.2.5
GitCommit: v1.2.5-0-g59923ef
docker-init:
Version: 0.19.0
GitCommit: de40ad0
What happened?
ScriptUtils splits an init script into a list of statements. This is valid syntax:
CREATE TABLE test (
x int
);
COMMENT ON COLUMN test.x
IS 'First sentence. '
'Second sentence';
But ScriptUtils converts this into these two statements:
CREATE TABLE test ( x int )
COMMENT ON COLUMN test.x IS 'First sentence. ' 'Second sentence'
The second statement isn't valid because the adjacent string literals need to be separated by at least one newline.
Relevant log output
Caused by: org.testcontainers.ext.ScriptUtils$ScriptStatementFailedException: Script execution failed (initPostgres.sql:2): COMMENT ON COLUMN test.x IS 'First sentence. ' 'Second sentence'
at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:63)
at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:38)
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:307)
... 83 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "'Second sentence'"
Position: 48
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2736)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2421)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:372)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:525)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:435)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:357)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:342)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:318)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:313)
at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:50)
... 85 common frames omitted
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ScriptUtils.java around executeDatabaseScript, using the PostgreSQL script shown in the report to reproduce the statement splitting. Verify the resulting statements preserve the required separation between adjacent string literals and that the script executes successfully against PostgreSQL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- databases, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100