Skip to content

fix: registryPattern to support port numbers in registry refs#2629

Open
AruneshDwivedi wants to merge 4 commits into
buildpacks:mainfrom
AruneshDwivedi:fix/registry-pattern-port
Open

fix: registryPattern to support port numbers in registry refs#2629
AruneshDwivedi wants to merge 4 commits into
buildpacks:mainfrom
AruneshDwivedi:fix/registry-pattern-port

Conversation

@AruneshDwivedi

@AruneshDwivedi AruneshDwivedi commented Jun 11, 2026

Copy link
Copy Markdown

canBeRegistryRef returns false on registry names with port numbers (e.g. localhost:5000/foo/bar). The registryPattern regex didn't include an optional port group.

Fixes #2536

@AruneshDwivedi AruneshDwivedi requested review from a team as code owners June 11, 2026 15:31
@github-actions github-actions Bot added the type/enhancement Issue that requests a new feature or improvement. label Jun 11, 2026
@github-actions github-actions Bot added this to the 0.41.0 milestone Jun 11, 2026

@kunalworldwide kunalworldwide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The regex fix is correct — (?::[0-9]+)? after the hostname segment allows port numbers like localhost:5000 or registry.example.com:5000 to be recognized as registry locators instead of falling through to InvalidLocator.

Test cases cover both localhost:5000/example/registry-cnb (port, no version) and registry.example.com:5000/example/[email protected] (port + version). Good coverage.

LGTM.

@jjbustamante

Copy link
Copy Markdown
Member

Hi @AruneshDwivedi, thanks for this contribution!

Could you take a look at the failing test?

@AruneshDwivedi

Copy link
Copy Markdown
Author

Pushed a fix — the regex was too permissive and was catching docker refs as registry refs. Added a check to exclude valid docker references from the registry pattern. CI should be green now.

canBeRegistryRef returns false on registry names with port numbers
e.g. localhost:5000/foo/bar was not recognized as a registry ref.

Fix: add optional port group (?::[0-9]+)? to the registryPattern regex.

Added test cases for:
- localhost:5000/example/registry-cnb
- registry.example.com:5000/example/[email protected]

Fixes buildpacks#2536

Signed-off-by: Arunesh Dwivedi <[email protected]>
The registryPattern regex only allowed a single path segment after
the hostname:port (e.g. /foo). Registry references like
localhost:5000/example/registry-cnb have multiple path segments.

Changed [a-z0-9\-\.]+ to [a-z0-9\-\.\/]+ after the initial slash
to allow multi-segment paths.

Signed-off-by: Arunesh Dwivedi <[email protected]>
Add test cases verifying that registry references with port numbers
(e.g. localhost:5000/example/registry-cnb) are correctly recognized
as RegistryLocator.

Signed-off-by: Arunesh Dwivedi <[email protected]>
canBeRegistryRef now checks if the locator is a valid docker reference
first. If name.ParseReference succeeds, the locator is classified as
PackageLocator instead of RegistryLocator. This prevents refs like
localhost:1234/example/package-cnb from being incorrectly matched by
the registry regex.

Signed-off-by: Arunesh Dwivedi <[email protected]>
@AruneshDwivedi AruneshDwivedi force-pushed the fix/registry-pattern-port branch from d11063a to 8cd88dd Compare June 27, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement Issue that requests a new feature or improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

canBeRegistryRef returns falso on registry names with port numbers

3 participants