Skip to content

Commit

Permalink
casts.go: Checking for different variants of Inf , Infinity and NaN(e…
Browse files Browse the repository at this point in the history
…liminating signs and checking for all possible cases)

Signed-off-by: sikehish <[email protected]>
  • Loading branch information
sikehish committed Dec 3, 2024
1 parent 0b7c771 commit dc80afc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion topdown/casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package topdown

import (
"strconv"
"strings"

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/topdown/builtins"
Expand All @@ -25,7 +26,10 @@ func builtinToNumber(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term
case ast.String:
strValue := string(a)

if strValue == "Inf" || strValue == "Infinity" || strValue == "NaN" {
trimmedVal := strings.TrimLeft(strValue, "+-")
lowerCaseVal := strings.ToLower(trimmedVal)

if lowerCaseVal == "inf" || lowerCaseVal == "infinity" || lowerCaseVal == "nan" {
return builtins.NewOperandTypeErr(1, operands[0].Value, "valid number string")
}

Expand Down

0 comments on commit dc80afc

Please sign in to comment.