PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
69 stars 36 forks source link

fix(feature flags) : Local evaluation : guard for null values when comparing person Properties #249

Closed Phanatic closed 3 months ago

Phanatic commented 3 months ago

Problem

The current behavior of stringifying undefined and null values to compare with operators can lead to invalid results in local evaluation.

This causes local evaluation to return true, while the /decide API does the right thing and returns false for undefined values in these properties.

Customer reported that local evaluation always evaluates a condition to true, when it should evaluate to false. The conditions in question are :

[
    {
        "key": "latestBuildVersion",
        "type": "person",
        "value": ".+",
        "operator": "regex"
    },
    {
        "key": "latestBuildVersionMajor",
        "type": "person",
        "value": "23",
        "operator": "gt"
    },
    {
        "key": "latestBuildVersionMinor",
        "type": "person",
        "value": "31",
        "operator": "gt"
    },
    {
        "key": "latestBuildVersionPatch",
        "type": "person",
        "value": "0",
        "operator": "gt"
    }
]

And the person properties passed into local evaluation are :

{
    "personProperties": {
        "latestBuildVersion": undefined,
        "latestBuildVersionMajor": undefined,
        "latestBuildVersionMinor": undefined,
        "latestBuildVersionPatch": undefined
    } as unknown as Record<string, string> 
}

Since we stringify all of the undefined values, the above call returns true when it should return false because the property values are undefined and not the string undefined.

Changes

Add a NULL_VALUES_ALLOWED_OPERATORS array of operators that allow NULL/UNDEFINED values which is just is_not right now . Any other operator will fail if the overrideValue is null or undefined

Release info Sub-libraries affected

Bump level

Libraries affected

Changelog notes

github-actions[bot] commented 3 months ago

Size Change: +366 B (+0.5%)

Total Size: 73.3 kB

Filename Size Change
posthog-node/lib/index.cjs.js 20 kB +183 B (+0.92%)
posthog-node/lib/index.esm.js 19.9 kB +183 B (+0.93%)
ℹ️ View Unchanged | Filename | Size | | :--- | :---: | | `posthog-web/lib/index.cjs.js` | 16.7 kB | | `posthog-web/lib/index.esm.js` | 16.7 kB |

compressed-size-action