Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/modernc.org/sqlite-1…
Browse files Browse the repository at this point in the history
….26.0
  • Loading branch information
TwiN authored Oct 11, 2023
2 parents d3de08f + 744d63a commit 8aa5f84
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 4 deletions.
10 changes: 9 additions & 1 deletion core/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ func isEqual(first, second string) bool {
return false
}
}

// test if inputs are integers
firstInt, err1 := strconv.ParseInt(first, 0, 64)
secondInt, err2 := strconv.ParseInt(second, 0, 64)
if err1 == nil && err2 == nil {
return firstInt == secondInt
}

return first == second
}

Expand Down Expand Up @@ -304,7 +312,7 @@ func sanitizeAndResolveNumerical(list []string, result *Result) (parameters []st
if duration, err := time.ParseDuration(element); duration != 0 && err == nil {
// If the string is a duration, convert it to milliseconds
resolvedNumericalParameters = append(resolvedNumericalParameters, duration.Milliseconds())
} else if number, err := strconv.ParseInt(element, 10, 64); err != nil {
} else if number, err := strconv.ParseInt(element, 0, 64); err != nil {
// It's not an int, so we'll check if it's a float
if f, err := strconv.ParseFloat(element, 64); err == nil {
// It's a float, but we'll convert it to an int. We're losing precision here, but it's better than
Expand Down
105 changes: 105 additions & 0 deletions core/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,111 @@ func TestCondition_evaluate(t *testing.T) {
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data.id > 0",
},
{
Name: "body-jsonpath-hexadecimal-int-using-greater-than",
Condition: Condition("[BODY].data > 0"),
Result: &Result{Body: []byte("{\"data\": \"0x1\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data > 0",
},
{
Name: "body-jsonpath-hexadecimal-int-using-equal-to-0x1",
Condition: Condition("[BODY].data == 1"),
Result: &Result{Body: []byte("{\"data\": \"0x1\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 1",
},
{
Name: "body-jsonpath-hexadecimal-int-using-equals",
Condition: Condition("[BODY].data == 0x1"),
Result: &Result{Body: []byte("{\"data\": \"0x1\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 0x1",
},
{
Name: "body-jsonpath-hexadecimal-int-using-equal-to-0x2",
Condition: Condition("[BODY].data == 2"),
Result: &Result{Body: []byte("{\"data\": \"0x2\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 2",
},
{
Name: "body-jsonpath-hexadecimal-int-using-equal-to-0xF",
Condition: Condition("[BODY].data == 15"),
Result: &Result{Body: []byte("{\"data\": \"0xF\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 15",
},
{
Name: "body-jsonpath-hexadecimal-int-using-equal-to-0xC0ff33",
Condition: Condition("[BODY].data == 12648243"),
Result: &Result{Body: []byte("{\"data\": \"0xC0ff33\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 12648243",
},
{
Name: "body-jsonpath-hexadecimal-int-len",
Condition: Condition("len([BODY].data) == 3"),
Result: &Result{Body: []byte("{\"data\": \"0x1\"}")},
ExpectedSuccess: true,
ExpectedOutput: "len([BODY].data) == 3",
},
{
Name: "body-jsonpath-hexadecimal-int-greater",
Condition: Condition("[BODY].data >= 1"),
Result: &Result{Body: []byte("{\"data\": \"0x01\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data >= 1",
},
{
Name: "body-jsonpath-hexadecimal-int-0x01-len",
Condition: Condition("len([BODY].data) == 4"),
Result: &Result{Body: []byte("{\"data\": \"0x01\"}")},
ExpectedSuccess: true,
ExpectedOutput: "len([BODY].data) == 4",
},
{
Name: "body-jsonpath-octal-int-using-greater-than",
Condition: Condition("[BODY].data > 0"),
Result: &Result{Body: []byte("{\"data\": \"0o1\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data > 0",
},
{
Name: "body-jsonpath-octal-int-using-equal",
Condition: Condition("[BODY].data == 2"),
Result: &Result{Body: []byte("{\"data\": \"0o2\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 2",
},
{
Name: "body-jsonpath-octal-int-using-equals",
Condition: Condition("[BODY].data == 0o2"),
Result: &Result{Body: []byte("{\"data\": \"0o2\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 0o2",
},
{
Name: "body-jsonpath-binary-int-using-greater-than",
Condition: Condition("[BODY].data > 0"),
Result: &Result{Body: []byte("{\"data\": \"0b1\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data > 0",
},
{
Name: "body-jsonpath-binary-int-using-equal",
Condition: Condition("[BODY].data == 2"),
Result: &Result{Body: []byte("{\"data\": \"0b0010\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 2",
},
{
Name: "body-jsonpath-binary-int-using-equals",
Condition: Condition("[BODY].data == 0b10"),
Result: &Result{Body: []byte("{\"data\": \"0b0010\"}")},
ExpectedSuccess: true,
ExpectedOutput: "[BODY].data == 0b10",
},
{
Name: "body-jsonpath-complex-int-using-greater-than-failure",
Condition: Condition("[BODY].data.id > 5"),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/TwiN/g8/v2 v2.0.0
github.com/TwiN/gocache/v2 v2.2.0
github.com/TwiN/health v1.6.0
github.com/TwiN/whois v1.1.3
github.com/TwiN/whois v1.1.7
github.com/coreos/go-oidc/v3 v3.6.0
github.com/gofiber/fiber/v2 v2.49.2
github.com/google/go-github/v48 v48.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/TwiN/gocache/v2 v2.2.0 h1:M3B36KyH24BntxLrLaUb2kgTdq8DzCnfod0IekLG57w
github.com/TwiN/gocache/v2 v2.2.0/go.mod h1:SnUuBsrwGQeNcDG6vhkOMJnqErZM0JGjgIkuKryokYA=
github.com/TwiN/health v1.6.0 h1:L2ks575JhRgQqWWOfKjw9B0ec172hx7GdToqkYUycQM=
github.com/TwiN/health v1.6.0/go.mod h1:Z6TszwQPMvtSiVx1QMidVRgvVr4KZGfiwqcD7/Z+3iw=
github.com/TwiN/whois v1.1.3 h1:DOexOmaCGuPCzzjcykE5MQQEiVawHHIIhVRyPUxbvWg=
github.com/TwiN/whois v1.1.3/go.mod h1:VOJAH4+3chAik5gva5zxJNXv2voEHjMNCf1y07sqj9w=
github.com/TwiN/whois v1.1.7 h1:eGzLOrWhpYLAGXD8boXh0bBKllN/EmuBsLqTJT4tC/U=
github.com/TwiN/whois v1.1.7/go.mod h1:VOJAH4+3chAik5gva5zxJNXv2voEHjMNCf1y07sqj9w=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down

0 comments on commit 8aa5f84

Please sign in to comment.