Skip to content

Keep full tag when parsing image names with extra colons - #12107

Open
SamuelAdigos wants to merge 1 commit into
testcontainers:mainfrom
SamuelAdigos:fix/5190-preserve-extra-tag-colons
Open

SamuelAdigos wants to merge 1 commit into
testcontainers:mainfrom
SamuelAdigos:fix/5190-preserve-extra-tag-colons

Conversation

@SamuelAdigos

@SamuelAdigos SamuelAdigos commented Oct 12, 2026 •

Copy link
Copy Markdown

Fixes #5190

DockerImageName.parse("neo4j:neo4j:4.4") silently dropped everything after the second :, yielding neo4j:neo4j.
The malformed name passed assertValid(), and any later error referred to an image name the user never wrote.

The tag is now everything after the first : of the remote name (split(":", 2)), matching how the tag-and-digest branch
already parses it (see testMalformedTagWithExtraColonIsRejected). The full name is preserved and assertValid() rejects
the malformed tag, since : is not allowed in Docker tags.

A trailing colon (myname:) previously failed with an ArrayIndexOutOfBoundsException; it now fails with a descriptive
IllegalArgumentException instead of producing an empty tag (which would otherwise reach the pull with tag="").

Note: a malformed name such as postgres:16:alpine previously resolved silently to postgres:16; it will now fail when
Docker is asked for the invalid tag.

I kept the change minimal rather than aligning the whole parser with the Docker reference grammar, as discussed in the
issue, to avoid rejecting names that are accepted today.

Tests

  • Added malformed names with extra colons to DockerImageNameTest.InvalidNames
  • Added testExtraColonInTagIsNotDropped and testEmptyTagIsRejected
  • ./gradlew :testcontainers:spotlessApply :testcontainers:checkstyleMain :testcontainers:checkstyleTest :testcontainers:japicmp
  • Ran the full CI testMatrix locally (core, all modules and examples). The only failures were environment-related
    (arm64 host, Rancher Desktop) and reproduce identically on main without this change.

Summary by CodeRabbit

  • Bug Fixes
    • Image names containing multiple colons are now parsed with the first colon separating the repository from the tag, preserving the remaining text as the tag.
    • Image names with an empty tag are now rejected with an error that identifies the invalid input.

`DockerImageName.parse("neo4j:neo4j:4.4")` silently dropped everything
after the second colon. The tag is now everything after the first colon
of the remote name, consistent with the tag-and-digest branch, so the
malformed name is preserved and rejected by `assertValid()`.

A trailing colon (`myname:`) now fails with a descriptive
`IllegalArgumentException` instead of an `ArrayIndexOutOfBoundsException`.

Fixes testcontainers#5190
@SamuelAdigos
SamuelAdigos requested a review from a team as a code owner October 12, 2026 03:14
@coderabbitai

coderabbitai Bot commented Oct 12, 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: 8f50de67-8fde-41f9-a7dd-7e76fdd94dd2

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb3c2d and a258935.


📒 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.



📝 Walkthrough

Walkthrough

DockerImageName now splits a tagged image name at the first colon, preserves the rest of the tag, and rejects an empty tag. Tests cover names with multiple colons and the empty-tag exception.

Changes

Docker image name parsing

Layer / File(s) Summary
Tag parsing and validation
core/src/main/java/org/testcontainers/utility/DockerImageName.java, core/src/test/java/org/testcontainers/utility/DockerImageNameTest.java
The parser uses the first colon to separate the repository from the tag and retains the remaining text as the tag. It rejects empty tags with an IllegalArgumentException. Tests cover multiple-colon names, canonical names, and the exception message.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: eddumelendez


Merge Risk: ⚪ Minimal · up to a2589

The change preserves malformed image-name input for validation and improves the empty-tag error; no material merge risk was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving the full tag when parsing image names with extra colons.
Description check Passed The description explains the bug, the parsing change, the resulting validation behavior, the trailing-colon case, the related issue, and the tests and validation performed.
Linked Issues check Passed Issue [#5190] requires the parser to preserve the supplied image name instead of dropping text after a second colon, and to reject the malformed reference. DockerImageName(String) uses `split(":", 2…
Out of Scope Changes check Passed The changes are limited to DockerImageName.java and its focused test class. The production change implements issue [#5190]. The added tests directly verify the changed parsing and validation behavio…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • 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

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

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.

Late ContainerFetchException on wrong image name

1 participant