Skip to content

Commit

Permalink
handle raw
Browse files Browse the repository at this point in the history
  • Loading branch information
chilagrow committed Aug 2, 2024
1 parent 531c946 commit de4af18
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package wire

import (
"errors"
"github.com/FerretDB/wire/wirebson"
"math"

"github.com/FerretDB/wire/internal/util/lazyerrors"
"github.com/FerretDB/wire/wirebson"
)

// validateNan returns error if float Nan was encountered.
Expand All @@ -30,13 +32,29 @@ func validateNan(v any) error {
}
}

case wirebson.RawDocument:
doc, err := v.Decode()
if err != nil {
return lazyerrors.Error(err)
}

return validateNan(doc)

case *wirebson.Array:
for i := range v.Len() {
if err := validateNan(v.Get(i)); err != nil {
return err
}
}

case wirebson.RawArray:
arr, err := v.Decode()
if err != nil {
return lazyerrors.Error(err)
}

return validateNan(arr)

case float64:
if math.IsNaN(v) {
return errors.New("NaN is not supported")
Expand Down

0 comments on commit de4af18

Please sign in to comment.