Skip to content

🐛 fix: Parsing of IPv6 addresses#3466

Merged
ReneWerner87 merged 8 commits into
mainfrom
update-parseAddr
May 22, 2025
Merged

🐛 fix: Parsing of IPv6 addresses#3466
ReneWerner87 merged 8 commits into
mainfrom
update-parseAddr

Conversation

@gaby
Copy link
Copy Markdown
Member

@gaby gaby commented May 22, 2025

Description

  • Expand the number of test cases for parseAddr()
  • Fix parsing of ipv6 addresses (found by OpenAI Codex)

@gaby gaby added this to the v3 milestone May 22, 2025
@gaby gaby added this to v3 May 22, 2025
@gaby gaby requested a review from a team as a code owner May 22, 2025 00:51
@gaby gaby requested review from ReneWerner87, efectn and sixcolors May 22, 2025 00:51
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2025

"""

Walkthrough

The test suite for address parsing utilities was expanded with additional cases to cover more address formats, including various IPv6, IPv4, hostname, Unix socket, and edge-case scenarios. Error messages in assertions were also improved to include the original input for clearer diagnostics. The address parsing function was enhanced to correctly handle bracketed IPv6 addresses and other complex address formats. No changes were made to exported or public entities.

Changes

File(s) Change Summary
helpers.go Enhanced parseAddr function to properly parse bracketed IPv6 addresses, handle unbracketed IPv6 literals, and improve port extraction logic.
helpers_test.go Added new test cases for address parsing, including IPv6, IPv4, hostnames, Unix sockets, and edge cases. Enhanced error messages in assertions to include the original address string.

Poem

In the warren of addresses, tests now abound,
IPv6 and Unix paths, all are found.
Hostnames and ports, every case in the mix,
With clearer errors, they're easy to fix.
A rabbit hops on, with a testing delight—
More cases, more coverage, all parsed just right! 🐇
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e97a79 and e70f6a0.

📒 Files selected for processing (1)
  • helpers_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • helpers_test.go
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.24.x, macos-latest)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-13)
  • GitHub Check: unit (1.23.x, macos-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: Analyse
  • GitHub Check: Compare
  • GitHub Check: repeated
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gaby gaby changed the title 🧹 chore: Add more test cases for parseAddr 🐛 fix: Parsing of IPv6 addresses May 22, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.45%. Comparing base (273df5f) to head (e70f6a0).
⚠️ Report is 431 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3466      +/-   ##
==========================================
+ Coverage   84.36%   84.45%   +0.08%     
==========================================
  Files         120      120              
  Lines       12140    12157      +17     
==========================================
+ Hits        10242    10267      +25     
+ Misses       1468     1462       -6     
+ Partials      430      428       -2     
Flag Coverage Δ
unittests 84.45% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
helpers.go (1)

569-600: Suggest adding RFC reference in function documentation

The function implementation now properly follows RFC 3986 for handling IPv6 addresses, but this isn't mentioned in the function documentation.

-func parseAddr(raw string) (string, string) { //nolint:revive // Returns (host, port)
+func parseAddr(raw string) (string, string) { //nolint:revive // Returns (host, port) according to RFC 3986
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffcc15a and 80c52c2.

📒 Files selected for processing (1)
  • helpers.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: Compare
  • GitHub Check: unit (1.23.x, macos-13)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: repeated
🔇 Additional comments (5)
helpers.go (5)

570-572: LGTM - Good defensive programming!

Adding a check for empty strings at the beginning of the function is a solid defensive programming practice. This prevents potential issues with empty inputs and makes the function more robust.


574-583: IPv6 bracketed address handling looks good

The implementation correctly handles IPv6 addresses enclosed in brackets according to RFC 3986. This properly extracts both the host (with brackets) and port from addresses like [2001:db8::1]:8080.


585-596: Robust handling of unbracketed IPv6 addresses

This enhancement correctly handles the case where an IPv6 address isn't properly bracketed but still needs to be parsed. By checking if the host part still contains colons after splitting at the last colon, the function can detect an unbracketed IPv6 address and treat the entire string as the host.


598-599: Comment adds clarity

The additional comment explains the fallback case when no colon is present in the input string, improving code readability.


569-600:

Details

✅ Verification successful

Verify IPv6 parsing with zone identifiers

The function should be able to handle IPv6 addresses with zone identifiers (e.g., [fe80::1%eth0]:8080), but it would be good to verify this with test cases.


🏁 Script executed:

#!/bin/bash
# Description: Search for IPv6 zone identifier test cases in the test file

# Look for tests with zone identifiers (%) in IPv6 addresses
rg -A 2 -B 2 "%.*\]" --glob "**/*_test.go"

Length of output: 2974


IPv6 zone identifier support validated

Existing tests in helpers_test.go cover zone-identifier scenarios:

  • {addr: "[fe80::1%lo0]:1234", host: "[fe80::1%lo0]", port: "1234"}
  • {addr: "[fe80::1%lo0]", host: "[fe80::1%lo0]", port: ""}

The parseAddr logic correctly handles bracketed IPv6 literals with zone identifiers, so no additional changes are needed.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: e70f6a0 Previous: 273df5f Ratio
Benchmark_Compress_Levels/Brotli_LevelBestCompression - B/op 5 B/op 0 B/op +∞

This comment was automatically generated by workflow using github-action-benchmark.

@gaby gaby added the codex label May 22, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6675218 and 00c6709.

📒 Files selected for processing (1)
  • helpers_test.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
helpers_test.go

[failure] 528-528:
File is not properly formatted (gofmt)

🪛 GitHub Actions: golangci-lint
helpers_test.go

[error] 528-528: File is not properly formatted (gofmt)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-13)
  • GitHub Check: Compare
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: Analyse
  • GitHub Check: repeated
🔇 Additional comments (2)
helpers_test.go (2)

519-532: Great enhancement to test coverage!

The additional test cases for the parseAddr function significantly improve coverage for various address formats, including IPv6 addresses without ports, IPv4 addresses without ports, hostnames, IPv6 link-local addresses with zone identifiers, and edge cases. This comprehensive set of test cases will help ensure the function correctly handles all these scenarios.

The improved error messages in the assertions also add clarity by including the original address that caused the test failure.

🧰 Tools
🪛 GitHub Check: lint

[failure] 528-528:
File is not properly formatted (gofmt)

🪛 GitHub Actions: golangci-lint

[error] 528-528: File is not properly formatted (gofmt)


536-537: Good improvement to error messages

Adding the original address string to the error messages makes test failures much more diagnostic-friendly.

Comment thread helpers_test.go Outdated
@gaby gaby requested a review from Copilot May 22, 2025 01:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the IPv6 address parsing logic and expands the associated test coverage for the parseAddr() function.

  • Added multiple test cases for IPv6 (with/without ports, with zone identifiers), IPv4, hostname, and bare port or empty cases.
  • Refined the parseAddr() function to handle empty input and bracketed IPv6 addresses more robustly.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
helpers_test.go New test cases added to thoroughly validate IPv6, IPv4, and socket addresses.
helpers.go Updated parseAddr() implements more precise handling of IPv6 and colon splitting.

gaby and others added 3 commits May 21, 2025 21:24
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@gofiber gofiber deleted a comment from coderabbitai Bot May 22, 2025
@ReneWerner87 ReneWerner87 merged commit 81edaf0 into main May 22, 2025
23 of 27 checks passed
@github-project-automation github-project-automation Bot moved this to Done in v3 May 22, 2025
@gaby gaby deleted the update-parseAddr branch May 22, 2025 11:05
@gaby gaby added the 📜 RFC Compliance Feature, implementation, or contribution adheres to relevant RFC standards. label Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug codex 📜 RFC Compliance Feature, implementation, or contribution adheres to relevant RFC standards. v3

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants