Skip to content

SyncEndpointUrl accepts endpoints that later panic or fail Display round-tripping #323

Description

@dumanoglu1

Summary

SyncEndpointUrl accepts HTTP endpoints that can later panic in websocket() or lose information when formatted and reparsed.

Cases

Maximum explicit HTTP port panics

let endpoint: SyncEndpointUrl = "http://localhost:65535".parse()?;
let _ = endpoint.websocket();

Parsing succeeds, but deriving the WebSocket URL executes http_port.checked_add(1).expect("port overflow") and panics. Invalid derived-port combinations should be rejected during parsing instead of failing later at runtime.

HTTP path and query are lost by Display

let endpoint: SyncEndpointUrl =
    "https://rpc.example.com/api/v1?key=value,wss=ws.example.com/websocket".parse()?;
let reparsed: SyncEndpointUrl = endpoint.to_string().parse()?;
assert_eq!(endpoint, reparsed);

Display reconstructs the HTTP side from only scheme, host, and port, so /api/v1?key=value is discarded. This violates the round-trip property already exercised by the module's tests.

IPv6 hosts are emitted without brackets

For an endpoint such as http://[::1]:8545,ws=8546, host_str() returns ::1 and Display writes it directly into the authority. The resulting string is not a valid bracketed IPv6 URL and cannot be reparsed reliably.

Expected behavior

  • accepted endpoint values should not panic when websocket() is called
  • parse -> Display -> parse should preserve the endpoint
  • IPv6 authorities should remain valid and bracketed

Proposed fix

Validate the derived WebSocket port during parsing and use URL-aware serialization so the HTTP path/query/fragment and IPv6 host syntax are preserved. Add focused regression tests for all three cases while retaining current canonical output for existing IPv4/default-port inputs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions