Skip to content

Preserve non-UTF-8 container output - #12183

Open
ZainnQureshii wants to merge 1 commit into
testcontainers:mainfrom
ZainnQureshii:fix/preserve-non-utf8-output
Open

ZainnQureshii wants to merge 1 commit into
testcontainers:mainfrom
ZainnQureshii:fix/preserve-non-utf8-output

Conversation

@ZainnQureshii

@ZainnQureshii ZainnQureshii commented Nov 24, 2026 •

Copy link
Copy Markdown

An ISO-8859-1 container log line containing café comes back as caf� when read with followOutput() and ToStringConsumer.toString(Charset), the path shown in docs/features/container_logs.md:58. The callback decodes and re-encodes each line as UTF-8 at core/src/main/java/org/testcontainers/containers/output/FrameConsumerResultCallback.java:138 before ToStringConsumer applies the requested charset at core/src/main/java/org/testcontainers/containers/output/ToStringConsumer.java:33.

Use a reversible ISO-8859-1 mapping for ANSI matching at core/src/main/java/org/testcontainers/containers/output/FrameConsumerResultCallback.java:143 and pass the original bytes through when color removal is disabled. Bytes outside the removed sequences reach the caller intact, so decoding the same line as ISO-8859-1 now returns café.

Both followOutput() overloads, snapshot and Compose logs, stdout and stderr in execInContainer(Charset, ...), the log wait strategy, and the Docker registry test helper use the same callback. The separate deprecated LogToStringContainerCallback reads an ASCII gateway address in production and has no caller-selected charset.

Refs #6163

Testing

  • ./gradlew --no-daemon --no-build-cache --no-scan --console=plain :testcontainers:test --tests org.testcontainers.containers.output.FrameConsumerResultCallbackTest exited 1 with the base callback. The callback turned café into caf� in both ISO-8859-1 cases. Restoring the UTF-8 conversion only when color removal is disabled made just the new test fail, also with exit 1.
  • ./gradlew --no-daemon --no-build-cache --no-scan --no-watch-fs --console=plain --max-workers=4 --continue --parallel -Porg.gradle.java.installations.fromEnv=TC_JDK11 checkstyleMain checkstyleTest spotlessCheck exited 0 for the root Gradle build. Gradle ran on Temurin 17.0.21 with TC_JDK11 pointing to Temurin 11.0.33 for HiveMQ's test compilation.
  • ./gradlew --no-daemon --no-build-cache --no-scan --console=plain --max-workers=4 --continue :testcontainers:check :testcontainers:test --tests org.testcontainers.containers.output.FrameConsumerResultCallbackTest exited 0. All 14 callback tests passed, including the ISO-8859-1 cases with ANSI colors removed and retained. The core check also ran Checkstyle, Spotless, Javadoc, japicmp, and the shaded JAR tests. The JAR tests reported 663 passed and 15 skipped by the API suite's assumptions.

The :testcontainers:test filter selected the in-memory callback tests to verify the fix without a Docker daemon. It excluded the other core test classes, including Docker-backed integration tests.

Prepared with AI assistance (Codex and Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Output containing non-UTF-8 characters, such as café, is now preserved when ANSI color codes are removed or retained. This prevents character corruption during output processing while keeping the requested color-code behavior unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZainnQureshii
ZainnQureshii requested a review from a team as a code owner November 24, 2026 17:38
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The callback now processes buffered bytes directly when matching ANSI codes. Tests verify that ISO-8859-1 text remains intact with ANSI-code removal enabled and disabled.

Changes: ANSI byte processing

Layer / File(s) Summary
Byte-preserving ANSI processing
core/src/main/java/org/testcontainers/containers/output/FrameConsumerResultCallback.java, core/src/test/java/org/testcontainers/containers/output/FrameConsumerResultCallbackTest.java
The callback processes ANSI codes using byte arrays and ISO-8859-1 matching. Tests check that café remains intact with and without ANSI-code removal.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: eddumelendez, sgtsilvio

Merge Risk: Minimal · up to 90333

This change preserves non-UTF-8 container output when the caller decodes it with the matching charset. No material merge risk was found.

Pre-merge checks: Passed 7

Check name Status Explanation
Title check Passed The title "Preserve non-UTF-8 container output" matches the main change. The callback now passes original bytes through when color removal is disabled, so ISO-8859-1 log content reaches the caller int…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the required template content in substance. It does not follow the repository template headings, but it gives a clear problem statement, the affected code paths, and the reason …
New Module Registration Passed The check "New module registration" applies only when the PR adds a new directory under modules/. The reviewed diff range (refs/coderabbit/pre-merge-check/base to head) changes exactly two files, both…
Public Api Compatibility Passed The PR changes two files: core/src/main/java/.../output/FrameConsumerResultCallback.java and a test file. The only src/main/java change is inside private static class LineConsumer, a private nes…
Tests For Behaviour Changes Passed Summary: PR #12183 (testcontainers/testcontainers-java, author ZainnQureshii) changes behavior in src/main/java and adds tests under src/test that exercise that change. The check passes. **Pro…
Full details: Title check

Explanation

The title "Preserve non-UTF-8 container output" matches the main change. The callback now passes original bytes through when color removal is disabled, so ISO-8859-1 log content reaches the caller intact instead of being re-encoded as UTF-8. The title is short, specific, and reads as a single sentence.

Full details: Description check

Explanation

The description covers the required template content in substance. It does not follow the repository template headings, but it gives a clear problem statement, the affected code paths, and the reason for the change. It also reports the commands run, their results, and the scope of testing. The template's pre-commit instruction to run checkstyle and spotless is covered by the reported spotless and checkstyle results. It has no explicit dependency-upgrade or new-module content, which does not apply to this change. It references the issue #6163. The author states that the Docker-backed integration tests were not run, which is a stated limitation and not a gap in the description.

Full details: New Module Registration

Explanation

The check "New module registration" applies only when the PR adds a new directory under modules/. The reviewed diff range (refs/coderabbit/pre-merge-check/base to head) changes exactly two files, both under core/: FrameConsumerResultCallback.java (M) and FrameConsumerResultCallbackTest.java (M). No files are added under modules/, so the check is inapplicable and passes by its own terms. The PR author (ZainnQureshii) and the other registration files were not evaluated because the applicability condition is not met.

Full details: Public Api Compatibility

Explanation

The PR changes two files: core/src/main/java/.../output/FrameConsumerResultCallback.java and a test file. The only src/main/java change is inside private static class LineConsumer, a private nested class. The edited members are consume() (private) and processAnsiColorCodes (package-private, with no modifier). Its signature changes from String processAnsiColorCodes(String) to byte[] processAnsiColorCodes(byte[]). Neither member is public or protected, and the class is private, so the change is outside the check's scope. The public surface of FrameConsumerResultCallback (addConsumer, onNext, onError, close, getCompletionLatch) is unchanged. The PR removes or renames no public or protected class, method, constructor, or field under src/main/java. The added test assertions are additive. The check therefore finds no failure condition.

Full details: Tests For Behaviour Changes

Explanation

Summary: PR #12183 (testcontainers/testcontainers-java, author ZainnQureshii) changes behavior in src/main/java and adds tests under src/test that exercise that change. The check passes. Production change (behavior fix): core/src/main/java/org/testcontainers/containers/output/FrameConsumerResultCallback.java. consume() no longer decodes and re-encodes each line as UTF-8. processAnsiColorCodes now works on byte[]. It maps bytes through ISO-8859-1 for ANSI regex matching. When color removal is disabled, it returns the original bytes unchanged. This changes what callers receive from followOutput() and ToStringConsumer.toString(Charset). Test change: core/src/test/java/org/testcontainers/containers/output/FrameConsumerResultCallbackTest.java adds: - preservesNonUtf8OutputWhenRemovingColors: ISO-8859-1 café with ANSI codes, removal enabled. Asserts decoded output is café\n. - preservesNonUtf8OutputWhenKeepingColors: same input, removal disabled. Asserts output equals the original payload. Both tests drive the changed callback path and assert the new behavior. The PR description reports that the base code fails these cases (caf�). I did not re-run that. The check does not depend on it. The documentation, build-only, and pure-refactoring exclusions do not apply. The behavior change has a matching test under src/test, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9f7ada8 and 9033384.

Files selected for processing: 2

  • core/src/main/java/org/testcontainers/containers/output/FrameConsumerResultCallback.java
  • core/src/test/java/org/testcontainers/containers/output/FrameConsumerResultCallbackTest.java

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant