Skip to content

Commit

Permalink
fix: support integers in to_number
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Sep 29, 2023
1 parent 2f1db57 commit c61a435
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pkg/functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,21 @@ func jpfToString(arguments []interface{}) (interface{}, error) {

func jpfToNumber(arguments []interface{}) (interface{}, error) {
arg := arguments[0]
if v, ok := arg.(float64); ok {
return v, nil
if arg == nil {
return nil, nil
}
if arg == true || arg == false {
return nil, nil
}
value := reflect.ValueOf(arg)
if value.CanFloat() {
return value.Float(), nil
}
if value.CanInt() {
return float64(value.Int()), nil
}

Check warning on line 719 in pkg/functions/functions.go

View check run for this annotation

Codecov / codecov/patch

pkg/functions/functions.go#L718-L719

Added lines #L718 - L719 were not covered by tests
if value.CanUint() {
return float64(value.Uint()), nil

Check warning on line 721 in pkg/functions/functions.go

View check run for this annotation

Codecov / codecov/patch

pkg/functions/functions.go#L721

Added line #L721 was not covered by tests
}
if v, ok := arg.(string); ok {
conv, err := strconv.ParseFloat(v, 64)
Expand All @@ -720,12 +733,6 @@ func jpfToNumber(arguments []interface{}) (interface{}, error) {
if _, ok := arg.(map[string]interface{}); ok {
return nil, nil
}
if arg == nil {
return nil, nil
}
if arg == true || arg == false {
return nil, nil
}
return nil, errors.New("unknown type")
}

Expand Down

0 comments on commit c61a435

Please sign in to comment.