Skip to content

fix: numeric port normalization; make LICENSE machine-detectable - #2

Merged
bomly-guy merged 2 commits into
mainfrom
claude/port-normalization
Aug 20, 2026
Merged

fix: numeric port normalization; make LICENSE machine-detectable#2
bomly-guy merged 2 commits into
mainfrom
claude/port-normalization

Conversation

@bomly-guy

@bomly-guy bomly-guy commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Two small fixes. Unrelated except that both lose information for a formatting reason.

Ports are normalized from their number, not their text

url.URL.Port preserves leading zeros, and the default-port check compared the port as a string. So https://host:0443/pkg kept its port while https://host/pkg did not — the two name one location, and ReconcileOrigin marked them a disagreement and discarded a valid origin.

Ports are now rewritten from the parsed number that the 1–65535 range check already computes. That also settles :08443 against :8443, which is the same problem one step along — and which a test in v0.4.0 had frozen as expected behaviour, asserting the leading zeros were "kept as written". Fixing only the default-port case would have left that asymmetry in place.

Reported by Codex review on bomly-cli#397 (comment 3809856511), where the rule now lives here rather than in the CLI.

LICENSE is detectable again

The file began with a blank line, leaving it 202 lines against the canonical Apache-2.0 text's 201. GitHub's licence detection does not classify it, so licenseInfo.spdxId is empty, and anything reading GitHub rather than deps.dev sees this module as unlicensed. That is exactly what surfaced as a code-scanning alert on a consumer: "Package license is unknown in pkg:golang/github.com/bomly-dev/bomly-sdk@v0.4.0".

deps.dev does report Apache-2.0, so the module's licensing was never in doubt — only its machine-readability. Removing the blank line leaves the text byte-identical to the canonical version (verified with a diff against the previous content minus that line).

Verification

  • go test ./..., go vet ./..., gofmt clean.
  • New cases for :0443, :080, and :08443, plus reconciliation asserting one port written two ways is one location while a genuinely different port still disagrees.
  • The numeric rewrite is mutation-checked: removing it fails a test.
  • FuzzPackageOrigin clean at 25s.

Worth a patch release when convenient — bomly-cli#397 is on v0.4.0 and does not need this to merge, but it carries the same reconciliation behaviour.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved URL normalization for HTTP and HTTPS addresses with ports.
    • Leading zeros in port numbers are now removed for consistent matching.
    • Default ports are omitted automatically.
    • IPv6 addresses with ports continue to normalize correctly.
    • Equivalent port formats now resolve consistently without conflicts.
  • Documentation

    • Added Apache License 2.0 terms and copyright attribution.

Two small fixes, unrelated except that both cost information for a formatting
reason.

`url.URL.Port` preserves leading zeros, and the default-port check compared the
port as text, so "https://host:0443/pkg" kept its port while "https://host/pkg"
did not. The two named one location and reconciled as a disagreement, throwing
away a valid origin. Ports are now rewritten from their parsed number, which
also settles ":08443" against ":8443" -- the same problem one step along, which
a test had quietly frozen as expected behaviour.

The LICENSE file began with a blank line, leaving it one line longer than the
canonical Apache-2.0 text. GitHub's licence detection does not classify it, so
`licenseInfo.spdxId` is empty and anything reading GitHub rather than deps.dev
sees this module as unlicensed -- which is what a Bomly scan of a consumer
reported. Removing the blank line leaves the text byte-identical to the
canonical version.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@bomly-guy, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 176a80cc-eeb2-476b-8136-3ce2d76d9933

📥 Commits

Reviewing files that changed from the base of the PR and between 84b1d59 and b3844d1.

📒 Files selected for processing (2)
  • origin.go
  • origin_test.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 25e93ff8-d5ec-4e43-a138-080a7e46136a

📥 Commits

Reviewing files that changed from the base of the PR and between be94bdd and 84b1d59.

📒 Files selected for processing (3)
  • LICENSE
  • origin.go
  • origin_test.go
💤 Files with no reviewable changes (1)
  • LICENSE

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The changes add an Apache License 2.0 file and update NormalizeOriginURL to canonicalize HTTP and HTTPS ports. Tests cover default-port removal, numeric normalization, and equivalent origin reconciliation.

Changes

Origin port normalization

Layer / File(s) Summary
Canonicalize origin ports
origin.go
NormalizeOriginURL removes default ports, strips leading zeros from other ports, and preserves IPv6 brackets.
Validate equivalent port spellings
origin_test.go
Tests cover default and non-default ports with leading zeros and verify reconciliation.
Add project license
LICENSE
Adds standard Apache License 2.0 terms with 2026 copyright attribution.

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

Merge Risk: ⚪ Minimal · up to 84b1d

This PR normalizes equivalent numeric ports and restores machine-detectable Apache-2.0 licensing with targeted verification; no actionable merge-blocking risk remains beyond normal checks and review.

Poem

A rabbit checks each port with care,
Drops default numbers from the fare.
Zeros hop away in line,
IPv6 brackets stay in sign.
“Equivalent origins now align!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes both main changes: numeric port normalization and machine-detectable licensing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/port-normalization

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84b1d598d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread origin.go Outdated
Rebuilding the host for a rewritten port restored brackets when the hostname
contained a colon. That is correct for every host url.Parse currently accepts --
a bracketed host that survives parsing is an IPv6 literal, since bracketed IPv4
and IPvFuture are both rejected -- but it infers the answer from the hostname's
contents when the URL already said it plainly.

Keying off whether the parsed host was bracketed says what is meant and stays
correct if host validation ever widens, where an unbracketed literal would name
a different host.

No behaviour change: a review suggested this as a fix for IPvFuture hosts such
as "[v1.foo]", which url.Parse rejects outright ("unexpected character"), so
that case never reaches this code.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bomly-guy
bomly-guy merged commit 978eda6 into main Aug 20, 2026
2 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.

1 participant