Skip to content

Reject empty required int16 and uint fields - #250

Closed
vitalivo wants to merge 1 commit into
gorilla:mainfrom
vitalivo:fix/required-integer-empty-values
Closed

vitalivo wants to merge 1 commit into
gorilla:mainfrom
vitalivo:fix/required-integer-empty-values

Conversation

@vitalivo

Copy link
Copy Markdown

The scalar-kind switch in isEmpty omits int16 and uint. Consequently, a form value of "" satisfies a required tag for those two types while the same input is correctly rejected for other scalar integers.

Include both kinds in the emptiness check. Regression tests use the public decoder to require an EmptyFieldError for an empty input and verify that an explicit "0" remains valid. Pointer semantics are unchanged.

Validation: both regressions fail before the fix. go test -race -cover ./... passes with 92.8% coverage, as do go vet ./... and staticcheck -tests=false ./.... Staticcheck with tests enabled reports two pre-existing unused fields in decoder_test.go.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant