Skip to content

fix: escape the container name in the Docker name filter - #3837

Merged
mdelapenya merged 1 commit into
testcontainers:mainfrom
bckground:fix-find-container-by-name-regex
Aug 6, 2026
Merged

fix: escape the container name in the Docker name filter#3837
mdelapenya merged 1 commit into
testcontainers:mainfrom
bckground:fix-find-container-by-name-regex

Conversation

@jcmfernandes

Copy link
Copy Markdown
Contributor

What does this PR do?

Quotes the name filter of the Docker container list API is a regular expression, so metacharacters in a container name are interpreted instead of matched literally.

Why is it important?

A lookup for "cache.1" also matches "cacheX1", and ReuseOrCreateContainer can reuse the wrong container.

Since container names may only include ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$ char . (dot) is the only metacharacter reachable through a legal container name.

Related issues

Not related to, by raised in #3051 by an LLM code review.

@jcmfernandes
jcmfernandes requested a review from a team as a code owner August 5, 2026 10:29
@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 4365cfa
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6a74532322e70c0008794e16
😎 Deploy Preview https://deploy-preview-3837--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d8aa7055-c59e-448b-a92f-aadd5a454c45

📥 Commits

Reviewing files that changed from the base of the PR and between 2f869d6 and 4365cfa.

📒 Files selected for processing (2)
  • docker.go
  • docker_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • docker_test.go
  • docker.go

Summary by CodeRabbit

  • Bug Fixes

    • Improved container-name matching so special characters are treated literally, preventing incorrect matches.
  • Tests

    • Added coverage verifying accurate lookups for names containing punctuation.

Walkthrough

The Docker provider now escapes container names before building its name filter regex. A regression test confirms that periods are treated literally.

Changes

Container name matching

Layer / File(s) Summary
Escape and validate name filter
docker.go, docker_test.go
findContainerByName now applies regexp.QuoteMeta to the requested name. The regression test confirms that test.1 does not match testX1.

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

Poem

I’m a rabbit checking each name,
A dot stays a dot in the matching game.
Literal strings guide the way,
Tests keep wildcards away.
Hop, hop—safe filters today!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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: escaping container names in the Docker name filter.
Description check ✅ Passed The description explains the Docker regex issue, its impact, and the reason for escaping container names.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@mdelapenya mdelapenya added the bug An issue with the library label Aug 5, 2026
@mdelapenya mdelapenya self-assigned this Aug 5, 2026
The name filter of the Docker container list API is a regular
expression, so metacharacters in a container name are interpreted
instead of matched literally. A lookup for "cache.1" therefore also
matches "cacheX1", and ReuseOrCreateContainer can reuse the wrong
container.
@jcmfernandes
jcmfernandes force-pushed the fix-find-container-by-name-regex branch from a8e2927 to 4365cfa Compare August 6, 2026 09:25
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@jcmfernandes

Copy link
Copy Markdown
Contributor Author

Rebased.

@mdelapenya mdelapenya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@mdelapenya
mdelapenya merged commit 1d054f6 into testcontainers:main Aug 6, 2026
285 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue with the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants