Skip to content

fix: trim whitespace in relay --ports list#1129

Open
tamimbinhakim wants to merge 1 commit into
schollz:mainfrom
tamimbinhakim:fix-relay-ports-whitespace
Open

fix: trim whitespace in relay --ports list#1129
tamimbinhakim wants to merge 1 commit into
schollz:mainfrom
tamimbinhakim:fix-relay-ports-whitespace

Conversation

@tamimbinhakim

Copy link
Copy Markdown
Contributor

Problem

croc relay --ports splits its value on , without trimming whitespace:

ports = strings.Split(c.String("ports"), ",")

So a natural invocation like:

croc relay --ports "9009, 9010, 9011"

produces port strings " 9010" and " 9011" (with a leading space). Those aren't valid ports — the per-port relay goroutines fail when binding/resolving them (tcp.Runnet.ResolveIPAddr), and the whitespace is also advertised to clients through the relay banner (tcpPorts := strings.Join(ports[1:], ",")).

The comma-separated --exclude flag already trims entries and drops empties; --ports did not, so this is an inconsistency rather than an intentional difference.

Fix

Add a small parseRelayPorts helper that splits on ,, trims each entry, and drops empties — mirroring the existing --exclude handling. "9009, 9010," is now parsed the same as "9009,9010".

Testing

  • Added TestParseRelayPorts (table-driven, matching the existing style in this package).
  • go test ./src/cli/ passes; go build ./... and go vet ./src/cli/ are clean.

`croc relay --ports "9009, 9010, 9011"` split the value on "," without
trimming, producing invalid port strings like " 9010" that fail to bind
and then get advertised to clients in the relay banner. Trim each entry
and drop empties so spaced or trailing-comma lists behave the same as
"9009,9010", matching how the comma-separated --exclude flag is already
handled.
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