Skip to content

Conversation

erikdubbelboer
Copy link
Collaborator

No description provided.

Copy link

@Copilot 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 adds validation to reject malformed IPv6 hostnames that contain mixed bracket syntax. It prevents the parser from accepting hostnames that incorrectly combine regular hostnames or IPv4 addresses with IPv6 bracket notation.

  • Added validation to detect and reject hostnames with misplaced '[' or ']' characters outside proper IPv6 format
  • Restructured the host parsing logic to check for invalid bracket usage before port validation
  • Added comprehensive tests to verify rejection of mixed bracket hostname patterns

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
uri.go Enhanced parseHost function to validate and reject hostnames with improper bracket usage
uri_test.go Added test cases to verify rejection of malformed IPv6 hostnames with mixed bracket syntax

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if !validOptionalPort(colonPort) {
return nil, fmt.Errorf("invalid port %q after host", colonPort)
} else {
if bytes.IndexByte(host, '[') != -1 || bytes.IndexByte(host, ']') != -1 {
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

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

The code performs two separate IndexByte operations on the same host slice. Consider combining these into a single loop or using bytes.ContainsAny(host, []byte("[]")) to check for both characters in one operation.

Suggested change
if bytes.IndexByte(host, '[') != -1 || bytes.IndexByte(host, ']') != -1 {
if bytes.ContainsAny(host, "[]") {

Copilot uses AI. Check for mistakes.

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