Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
just sysinfo
- name: Run Go Test
run: |
just init tidy lint test
just init tidy lint tests

8 changes: 7 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ default:
tidy:
go mod tidy

# run specific unit test
[group('build')]
[no-cd]
test unit:
go test -v -count=1 -race -run {{unit}} 2>/dev/null

# run tests across source tree
[group('build')]
test:
tests:
go test -v -race -count=1 ./...

# apply go vet command on source tree
Expand Down
15 changes: 9 additions & 6 deletions forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,23 @@ func BoolOr(b *bool, alt bool) Parser {
}

func (p *boolParser) Parse(values []string) error {
var b bool
var err error

switch {
case len(values) > 1:
return ErrMulitpleValues
case len(values) == 0 && p.required:
return ErrNoValue
case len(values) == 0:
return nil
}

b, err := strconv.ParseBool(values[0])
if err != nil {
return err
case values[0] == "on":
// HTML checkbox uses "on" to indicate checked
b = true
default:
b, err = strconv.ParseBool(values[0])
}

*p.destination = b
return nil
return err
}
15 changes: 15 additions & 0 deletions forms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ func Test_Parse_float_malformed(t *testing.T) {
must.Error(t, err)
}

func Test_Parse_Bool_checkbox_on(t *testing.T) {
t.Parallel()

data := url.Values{
"checkbox": []string{"on"},
}

var cb bool
err := ParseValues(data, Schema{
"checkbox": Bool(&cb),
})
must.NoError(t, err)
must.True(t, cb)
}

func Test_Parse_bool_value_missing(t *testing.T) {
t.Parallel()

Expand Down
Loading