fix(utils): normalize unbracketed IPv6 literals for probing#7045
fix(utils): normalize unbracketed IPv6 literals for probing#7045dwisiswant0 wants to merge 1 commit intodevfrom
Conversation
WalkthroughAdds IPv6 input normalization to the HTTP probe utility. A new helper function normalizeProbeInput parses unbracketed IPv6 literals and returns them in bracketed form, while preserving inputs that already contain schemes or brackets. The ProbeURL function now uses normalized input for scheme determination and URL formation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Fix ambiguous interpretation of IPv6 addresses like "::1:8065" by bracketing them before URL formation to make sure they are treated as hosts rather than "host:port" pairs. Close #6960 Signed-off-by: Dwi Siswanto <git@dw1.io>
131f31a to
0eba859
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/utils/http_probe_test.go (1)
78-96: Consider adding edge case coverage.The normalization tests cover the main scenarios well. For completeness, consider adding test cases for:
- Input already containing a scheme:
"http://example.com"→"http://example.com"- Bare IPv4 without port:
"127.0.0.1"→"127.0.0.1"These are explicitly handled by
normalizeProbeInputbut not exercised by tests.🧪 Suggested additional test cases
tests := []struct { input string expected string }{ {"::1:8065", "[::1:8065]"}, {"fe80::1", "[fe80::1]"}, {"[::1]:8065", "[::1]:8065"}, {"127.0.0.1:8080", "127.0.0.1:8080"}, {"example.com:443", "example.com:443"}, + {"http://example.com", "http://example.com"}, + {"127.0.0.1", "127.0.0.1"}, }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/utils/http_probe_test.go` around lines 78 - 96, Add two edge-case table-driven tests to TestNormalizeProbeInput to cover inputs with an explicit scheme and a bare IPv4 address: include the cases `"http://example.com"` expecting `"http://example.com"` and `"127.0.0.1"` expecting `"127.0.0.1"`, so normalizeProbeInput is exercised for those branches; update the tests slice in TestNormalizeProbeInput to include these two entries and run the same t.Run/require.Equal assertion flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/utils/http_probe_test.go`:
- Around line 78-96: Add two edge-case table-driven tests to
TestNormalizeProbeInput to cover inputs with an explicit scheme and a bare IPv4
address: include the cases `"http://example.com"` expecting
`"http://example.com"` and `"127.0.0.1"` expecting `"127.0.0.1"`, so
normalizeProbeInput is exercised for those branches; update the tests slice in
TestNormalizeProbeInput to include these two entries and run the same
t.Run/require.Equal assertion flow.
Neo - PR Security ReviewNo security issues found Highlights
Comment |
Proposed changes
fix(utils): normalize unbracketed IPv6 literals for probing
Fix ambiguous interpretation of IPv6 addresses
like "::1:8065" by bracketing them before URL
formation to make sure they are treated as hosts
rather than "host:port" pairs.
Close #6960
Proof
Checklist
Summary by CodeRabbit
Bug Fixes
Tests