fix: trim whitespace in relay --ports list#1129
Open
tamimbinhakim wants to merge 1 commit into
Open
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
croc relay --portssplits its value on,without trimming whitespace:So a natural invocation like:
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.Run→net.ResolveIPAddr), and the whitespace is also advertised to clients through the relay banner (tcpPorts := strings.Join(ports[1:], ",")).The comma-separated
--excludeflag already trims entries and drops empties;--portsdid not, so this is an inconsistency rather than an intentional difference.Fix
Add a small
parseRelayPortshelper that splits on,, trims each entry, and drops empties — mirroring the existing--excludehandling."9009, 9010,"is now parsed the same as"9009,9010".Testing
TestParseRelayPorts(table-driven, matching the existing style in this package).go test ./src/cli/passes;go build ./...andgo vet ./src/cli/are clean.