Skip to content

Treat an uppercase first path component as a registry in DockerImageName - #12187

Open
MikeFTV wants to merge 1 commit into
testcontainers:mainfrom
MikeFTV:fix/docker-image-name-uppercase-registry
Open

MikeFTV wants to merge 1 commit into
testcontainers:mainfrom
MikeFTV:fix/docker-image-name-uppercase-registry

Conversation

@MikeFTV

@MikeFTV MikeFTV commented Nov 28, 2026 •

Copy link
Copy Markdown

Why

DockerImageName.parse("FOO/bar") gives an empty registry and assertValid() then throws IllegalArgumentException. Docker's own reference parser (splitDockerDomain in distribution/reference) takes the first path component as a registry when it contains a dot or a colon, is localhost, or is not all lowercase, because a repository path is always lowercase. DockerImageName only knew the first three rules. The same happens for Foo/bar, LOCALDOMAIN/fooo and LOCALDOMAIN/fooo/bar.

Refs #12186.

What changes

  • A private isRegistry(String firstComponent) in DockerImageName holds the rule, with the new "not all lowercase" case (toLowerCase(Locale.ROOT)).
  • Both deprecated constructors (the single-string one that parse uses, and the name-plus-version one) call it instead of repeating the three-part condition.
  • No public signature changes, so japicmp is not affected.
  • A name that is all lowercase and has no dot, colon or localhost in its first component (repo/my-name) still has an empty registry; the existing repo/myname cases cover this.

Tests

  • DockerImageNameTest: four new Parsing cases (FOO/bar, Foo/bar:1.0, LOCALDOMAIN/fooo/bar, LOCALDOMAIN/fooo@sha256:...) and two new ValidNames entries. Parsing also runs the second constructor for the cases that have a version.
  • ./gradlew :testcontainers:test --tests '*DockerImageNameTest': 51 tests, all pass. With core/src/main restored to main: 51 tests, 6 fail (the new cases).
  • ./gradlew :testcontainers:spotlessApply :testcontainers:checkstyleMain :testcontainers:checkstyleTest: passes, no file changed by spotless.
  • ./gradlew :testcontainers:test --tests 'org.testcontainers.utility.*': 160 tests, 3 fail: ImageNameSubstitutorTest.testImageNameSubstitutorToString and two ResourceReaperTest cases. ImageNameSubstitutorTest also fails on main ("replacementImage is null"). ResourceReaperTest passes when run alone with this change; it failed in the run after ImageNameSubstitutorTest in the same JVM (on main, the same two-class run did not fail it, so I cannot say it is unrelated to ordering with certainty).
  • Not run: the rest of ./gradlew :testcontainers:check (japicmp, javadoc, other modules).

Summary by CodeRabbit

  • Bug Fixes
    • Docker image names with uppercase registry or domain components are now parsed correctly, including tagged and digest-qualified references. Uppercase first path components are recognized as registries, while components without registry indicators continue to be treated as part of the repository path. This improves handling of image references across common naming formats.

Docker's reference parser takes the first path component as a registry when it
contains a dot or a colon, is localhost, or is not all lowercase. DockerImageName
only knew the first three, so FOO/bar parsed with an empty registry and
assertValid() threw.
@MikeFTV
MikeFTV requested a review from a team as a code owner November 28, 2026 06:27
@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 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Both deprecated DockerImageName constructors now use a shared rule to identify registry components. Uppercase registry names are recognized, and parsing tests cover uppercase names with tags, paths, and digests.

Changes: Docker image registry detection

Layer / File(s) Summary
Registry detection and parsing coverage
core/src/main/java/org/testcontainers/utility/DockerImageName.java, core/src/test/java/org/testcontainers/utility/DockerImageNameTest.java
Both constructors use a shared check that recognizes a first component containing uppercase characters as a registry. Tests add uppercase registry cases for valid names and parsing, including tagged and digest-qualified images.

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

Change: Bug fix

Possibly related issues

  • testcontainers/testcontainers-java#12186 — The issue describes uppercase first path components being parsed without a registry. This change adds the corresponding detection rule and parsing cases.

Suggested reviewers: eddumelendez

Merge Risk: Minimal · up to e1d56

Image names with an uppercase first path component, such as FOO/bar, are now parsed as having a registry, consistent with Docker. Lowercase repository paths behave as before. No merge-blocking risk was identified.

Pre-merge checks: Passed 7

Check name Status Explanation
Title check Passed The title names the main change: an uppercase first path component is now treated as a registry in DockerImageName. The raw summary and objectives confirm a private isRegistry rule that adds a not-all…
Description check Passed The description follows the template's intent. It explains the motivation (FOO/bar gives an empty registry), lists the changes, includes tests run with their results, and references issue #12186. The …
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.
New Module Registration Passed The check "New module registration" applies only when the PR adds a new directory under modules/. The changed-file inventory (git diff --name-status between the review base and head) lists only two mo…
Public Api Compatibility Passed The check fails only when the PR removes, renames, or changes the signature, return type, or visibility of a public or protected API under src/main/java without keeping a deprecated predecessor. I ins…
Tests For Behaviour Changes Passed The PR changes behaviour in production code. In core/src/main/java/org/testcontainers/utility/DockerImageName.java, both deprecated constructors now call a new private isRegistry method. That method a…
Full details: Title check

Explanation

The title names the main change: an uppercase first path component is now treated as a registry in DockerImageName. The raw summary and objectives confirm a private isRegistry rule that adds a not-all-lowercase case, so the title matches the changeset.

Full details: Description check

Explanation

The description follows the template's intent. It explains the motivation (FOO/bar gives an empty registry), lists the changes, includes tests run with their results, and references issue #12186. The template's generic notes (new module steps, dependency upgrades) do not apply to this change, and the description covers the required bug-fix content: the broken behaviour and how the change fixes it.

Full details: New Module Registration

Explanation

The check "New module registration" applies only when the PR adds a new directory under modules/. The changed-file inventory (git diff --name-status between the review base and head) lists only two modified files: core/src/main/java/org/testcontainers/utility/DockerImageName.java and core/src/test/java/org/testcontainers/utility/DockerImageNameTest.java. No file under modules/ is added or changed, so no new module directory is introduced. The check is inapplicable and passes.

Full details: Public Api Compatibility

Explanation

The check fails only when the PR removes, renames, or changes the signature, return type, or visibility of a public or protected API under src/main/java without keeping a deprecated predecessor. I inspected the full diff against the review base. The only main-source change is in core/src/main/java/org/testcontainers/utility/DockerImageName.java. It adds a private static boolean isRegistry(String) helper and replaces the inline registry condition in the two existing @Deprecated constructors with calls to that helper. Both constructor signatures, their visibility, and the class declaration are unchanged. The added java.util.Locale import is internal. The only other changed file is the test class DockerImageNameTest.java. The change is additive or internal, so the check passes. Scope: this verdict covers the diff only. It does not cover japicmp, which the PR author reports was not run.

Full details: Tests For Behaviour Changes

Explanation

The PR changes behaviour in production code. In core/src/main/java/org/testcontainers/utility/DockerImageName.java, both deprecated constructors now call a new private isRegistry method. That method also treats a first path component as a registry when it is not all lowercase, so names such as FOO/bar no longer parse with an empty registry. The same PR adds tests in core/src/test/java/org/testcontainers/utility/DockerImageNameTest.java that exercise this change: ValidNames entries FOO/bar and LOCALDOMAIN/fooo/bar:1.0, and Parsing cases for FOO/bar, Foo/bar:1.0, LOCALDOMAIN/fooo/bar, and LOCALDOMAIN/fooo@sha256:.... The PR description reports that these cases fail when core/src/main is restored to main. I did not run the tests. The check requires a test for a src/main behaviour change, and that requirement is met. The change is not documentation-only, build-only, or a pure refactor, so the check applies.

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 a736c02 and e1d5601.

Files selected for processing: 2

  • core/src/main/java/org/testcontainers/utility/DockerImageName.java
  • core/src/test/java/org/testcontainers/utility/DockerImageNameTest.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