fix: allow signed integer fields in port validation - #1633
Merged
nodivbyzero merged 3 commits intoSep 17, 2026
Merged
Conversation
ilovelinux
approved these changes
Sep 15, 2026
ilovelinux
left a comment
There was a problem hiding this comment.
LGTM, a minor suggestion to explicitly reject unsupported values.
Comment on lines
+3054
to
+3056
| default: | ||
| val := field.Uint() | ||
| return val >= 1 && val <= 65535 |
There was a problem hiding this comment.
I'd implement the same logic implemented in isIso3166AlphaNumeric and similar functions. The panic error is going to be more explicit.
Suggested change
| default: | |
| val := field.Uint() | |
| return val >= 1 && val <= 65535 | |
| case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: | |
| val := field.Uint() | |
| return val >= 1 && val <= 65535 | |
| default: | |
| panic(fmt.Sprintf("Bad field type %s", field.Type())) |
nodivbyzero
reviewed
Sep 16, 2026
| # Port | ||
|
|
||
| This validates that the value falls within the valid port number range of 1 to 65,535. | ||
| This validates that a signed or unsigned integer value falls within the valid port number range of 1 to 65,535. |
Contributor
There was a problem hiding this comment.
Suggested change
| This validates that a signed or unsigned integer value falls within the valid port number range of 1 to 65,535. | |
| This validates that an integer value (signed or unsigned) falls within the valid port range of 1-65,535. |
nodivbyzero
previously approved these changes
Sep 16, 2026
nodivbyzero
left a comment
Contributor
There was a problem hiding this comment.
Thanks for contributing! The changes look good to me with just one minor doc change request.
nodivbyzero
approved these changes
Sep 17, 2026
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.
Fixes Or Enhances
The
portvalidator panics on signed integer fields, including a validint(8080). This prevents validating port values using the types used by Go's standard networking APIs.Handle signed integer kinds with
reflect.Value.Int()while preserving unsigned integer validation and the existing 1–65535 range. Extend the regression tests to cover signed kinds, named integer types, negative and out-of-range values, and unsigned compatibility. Update the port documentation accordingly.Validation:
go test . -run '^Test_port_validator$' -count=1go test -race -covermode=atomic -coverprofile=../validator-coverage.out ./...go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.1 runFixes #1632.