Skip to content

feat(restore): encode source registry hosts with ports for --preserve-source-registry - #2402

Merged
TerryHowe merged 2 commits into
oras-project:mainfrom
Orion777-cmd:feat/restore-encode-registry-ports
Nov 27, 2026
Merged

TerryHowe merged 2 commits into
oras-project:mainfrom
Orion777-cmd:feat/restore-encode-registry-ports

Conversation

@Orion777-cmd

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
--preserve-source-registry now encodes the source registry host as a repository path component instead of rejecting hosts with a port, as described in #2358: the host is lowercased and the port : is replaced by _ (registry.lan:5000 → registry.lan_5000). IPv6 literal hosts are rejected with a recommendation. Target repositories longer than 255 characters are rejected before anything is pushed, since properties.NewReference only checks the pattern.

Two notes from implementing it:

  • properties.NewReference already lowercases the registry, so uppercase hosts worked with the flag before this change, and Registry.example.com/app and registry.example.com/app are the same source rather than a collision. a:5000 and a_5000 do collide and are reported.
  • --dry-run needed no change; it prints the encoded targets.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2398

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update? (flag help and example updated)
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header? (no new files)

…-source-registry

Encode the source registry host as a repository path component instead
of rejecting hosts with a port: the host is lowercased and the ':' before
a port is replaced by '_' (registry.lan:5000 -> registry.lan_5000). Host
names cannot contain '_', so different hosts never encode to the same
component. IPv6 literal hosts are rejected with a recommendation.

Reject target repositories longer than 255 characters before anything
is pushed, as oras-go only validates the repository pattern.

Fixes oras-project#2398

Signed-off-by: orion777-cmd <[email protected]>
@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.93%. Comparing base (06d6343) to head (e2144aa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2402      +/-   ##
==========================================
+ Coverage   90.86%   90.93%   +0.06%     
==========================================
  Files         158      158              
  Lines        7172     7180       +8     
==========================================
+ Hits         6517     6529      +12     
+ Misses        382      380       -2     
+ Partials      273      271       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe TerryHowe 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

@TerryHowe
TerryHowe merged commit ed8cabb into oras-project:main Nov 27, 2026
10 checks passed
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.

feat(restore): encode source registry hosts with ports for --preserve-source-registry

2 participants