Skip to content

Fix init script decoding with configurable charsets - #12082

Open
dlwhdgus0810 wants to merge 5 commits into
testcontainers:mainfrom
dlwhdgus0810:fix/init-script-charset
Open

dlwhdgus0810 wants to merge 5 commits into
testcontainers:mainfrom
dlwhdgus0810:fix/init-script-charset

Conversation

@dlwhdgus0810

@dlwhdgus0810 dlwhdgus0810 commented Sep 16, 2026 •

Copy link
Copy Markdown

Windows-1252 initialization scripts are decoded as UTF-8, corrupting accented characters before SQL reaches the database. Add an explicit Charset overload to ScriptUtils.runInitScript and JdbcDatabaseContainer.withInitScriptCharset so callers can select the script encoding. Existing calls continue to use UTF-8.

The container setting applies to all scripts configured through withInitScript or withInitScripts. JDBC URL TC_INITSCRIPT remains UTF-8, as documented. This changes file decoding, not the database character set.

Regression coverage uses a Windows-1252 fixture containing é and UTF-8 controls. The Windows-1252 case failed on the original implementation. All 62 database-commons and JDBC tests pass, along with both module check tasks (Checkstyle, Spotless, Javadoc, and API compatibility). Docker-backed Oracle integration was not run.

Fixes #8776.

Summary by CodeRabbit

  • New Features
    • JDBC initialization scripts can be read using a configured character encoding; UTF-8 remains the default.
  • Documentation
    • Clarified that configured initialization scripts default to UTF-8 and follow the container’s charset setting, while scripts loaded through TC_INITSCRIPT are always read as UTF-8.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 28573aae-05b7-4c35-82ad-2f3a4b204a1a
📥 Commits

Reviewing files that changed from the base of the PR and between cf0731f and e5071ad.

📒 Files selected for processing: 3
  • modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
  • modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java
  • modules/postgresql/src/test/java/org/testcontainers/postgresql/PostgreSQLContainerTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

📝 Walkthrough

JDBC initialization scripts can now use a configured charset. Script loading defaults to UTF-8, and JDBC containers pass the configured charset to the script loader. Tests cover UTF-8 and Windows-1252 scripts.

Changes: Initialization script charset support

Layer / File(s) Summary
Script loading charset contract
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java, modules/database-commons/src/test/java/org/testcontainers/ext/ScriptUtilsTest.java, modules/database-commons/src/test/resources/init-*.sql
ScriptUtils adds a charset-aware overload and keeps UTF-8 as the default. Unit tests and SQL fixtures cover UTF-8, Windows-1252, and null charset handling.
JDBC container integration
modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java, modules/postgresql/src/test/java/org/testcontainers/postgresql/PostgreSQLContainerTest.java, modules/postgresql/src/test/resources/somepath/init_postgresql_windows-1252.sql, docs/modules/databases/jdbc.md
JdbcDatabaseContainer adds withInitScriptCharset and passes the setting to script loading. A PostgreSQL integration test checks a Windows-1252 script. The JDBC documentation describes charset defaults and the TC_INITSCRIPT behavior.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant JdbcDatabaseContainer
  participant ScriptUtils
  participant DatabaseDelegate
  JdbcDatabaseContainer->>ScriptUtils: Run script with configured charset
  ScriptUtils->>DatabaseDelegate: Execute decoded SQL statements
Loading

Suggested reviewers: kiview

Merge Risk: ⚪ Minimal · up to e5071

Container-configured initialization scripts can use the selected decoding charset without changing the default or JDBC URL script behavior. No merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: configurable character-set handling for initialization scripts.
Description check Passed The description explains the bug, the implemented APIs, default behavior, scope, regression coverage, test results, skipped integration testing, and linked issue.
Linked Issues check Passed The changes satisfy the coding requirements in [#8776]. ScriptUtils.runInitScript accepts a selected Charset, and the existing overload retains UTF-8. JdbcDatabaseContainer.withInitScriptCharset…
Out of Scope Changes check Passed The changes remain within [#8776]. Production changes configure initialization-script decoding. Tests, encoded fixtures, and documentation verify or explain that behavior. No unrelated production chan…
Full details: Linked Issues check

Explanation

The changes satisfy the coding requirements in [#8776]. ScriptUtils.runInitScript accepts a selected Charset, and the existing overload retains UTF-8. JdbcDatabaseContainer.withInitScriptCharset applies the selected charset to scripts configured with withInitScript and withInitScripts. Tests cover UTF-8, Windows-1252, null validation, and container execution. Documentation records the UTF-8 behavior of TC_INITSCRIPT.

Full details: Out of Scope Changes check

Explanation

The changes remain within [#8776]. Production changes configure initialization-script decoding. Tests, encoded fixtures, and documentation verify or explain that behavior. No unrelated production change is identified.

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

kiview and others added 3 commits October 18, 2026 22:34
Replace the inline docs example with a codeinclude from a new
PostgreSQL integration test that also covers the windows-1252 init
script end to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The container wiring is covered end to end by the PostgreSQL init
script charset test, and decoding by ScriptUtilsTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kiview

kiview commented Oct 18, 2026

Copy link
Copy Markdown
Member

Thank you @dlwhdgus0810, made some small adjustments in follow-up commits, and going to merge it once CI is green.

@kiview
kiview enabled auto-merge (squash) October 18, 2026 20:49
@kiview kiview added this to the next milestone Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: init script UTF8 conversion breaks encoding used in database when not in UTF8

2 participants