fix: not_regex should handle all value types like regex - #305
Conversation
The not_regex operator used a manual string/int type switch and returned an error for any other type, most notably float64 (what JSON numbers deserialize to), so it failed on a numeric property value even though regex handled the same value. Coerce both the pattern and the property value with valueToString, mirroring the regex operator, and add a regression test.
|
This pairs with the exact/is_not consistency fix in #299 and is independent of it. The practical trigger is common: a not_regex flag condition on a numeric property (an ID, a version code, an age) that arrives as a JSON number, which becomes float64 in Go, currently errors instead of evaluating. Routing through valueToString keeps not_regex in step with regex for every value type. |
dustinbyrne
left a comment
There was a problem hiding this comment.
hey @eeshsaxena, thanks for another pull request here! i ran an agentic review for compatibility, and it had one minor finding i've described below. it's small enough in scope that it seems worth fixing.
| // string/int type switch errored on other types, most notably float64, | ||
| // which is what JSON numbers deserialize to, so not_regex failed on a | ||
| // numeric property value even though regex handled it. | ||
| r, err := getOrCompileRegex(valueToString(value)) |
There was a problem hiding this comment.
a bit of an edge case, but since we're in here, one minor deviation from the feature flags evaluation service is if value is nil, the string representation returned is <nil>
e.g. with the following properties:
{ "k": null }and condition:
{
"key": "k",
"operator": "not_regex",
"value": "^null$"
}this would match remotely, but not match here.
|
also, your commits will need to be signed in order to be eligible for merge |
Problem
The
regexandnot_regexoperators handle value types differently.regexcoerces both sides withvalueToString, so it accepts strings, ints, floats, and bools:not_regexinstead uses a manualstring/inttype switch and returns an error for anything else:The important gap is
float64: JSON numbers deserialize tofloat64, so anot_regexcondition on a numeric property value errors out even though the same value works withregex:Fix
Make
not_regexmirrorregex, coercing both the pattern and the property value withvalueToString. This handles all value types and keeps the two operators consistent. AddedTestMatchPropertyNotRegexHandlesAllValueTypes(string, int, float64).Testing
go test .passes (full package suite, including the new test).