-
Notifications
You must be signed in to change notification settings - Fork 21
fix(flags): honor versioned local property matching #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "PostHog": patch | ||
| --- | ||
|
|
||
| Honor definition snapshot `property_matching_version` during local feature flag evaluation. Version 2 uses normalized scalar and list-member equality instead of aggregate boolean coercion, including known null properties; missing and other versions retain legacy matching. Empty filter lists keep recursive truthiness in both modes. Matching semantics remain tied to cached definitions across refreshes and 304 responses. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,8 +190,31 @@ internal bool IsSuffixOfAsciiIgnoreCase(object? other) => | |
| /// </summary> | ||
| /// <param name="overrideValue">The override value.</param> | ||
| /// <returns><c>true</c> if the override value is an "exact" match for this value.</returns> | ||
| public bool IsExactMatch(object? overrideValue) | ||
| public bool IsExactMatch(object? overrideValue) => IsExactMatch(overrideValue, propertyMatchingVersion: null); | ||
|
|
||
| internal bool IsExactMatch(object? overrideValue, int? propertyMatchingVersion) | ||
| { | ||
| if (propertyMatchingVersion == 2) | ||
| { | ||
| // Empty filters retain recursive legacy truthiness, not empty ANY membership. | ||
| if (ListOfStrings is { Count: 0 }) | ||
| { | ||
| return IsTruthyPropertyValue(overrideValue); | ||
| } | ||
|
|
||
| var comparand = overrideValue is decimal decimalValue | ||
| ? StringifyDecimal(decimalValue) | ||
| : ToInvariantString(overrideValue); | ||
| return this switch | ||
| { | ||
| { ListOfStrings: { } values } => values.Any(value => UnicodeLowercaseEquals(value, comparand)), | ||
| { StringValue: { } value } => UnicodeLowercaseEquals(value, comparand), | ||
| { BooleanValue: { } value } => UnicodeLowercaseEquals(value ? "true" : "false", comparand), | ||
| { CohortId: { } value } => UnicodeLowercaseEquals(value.ToString(CultureInfo.InvariantCulture), comparand), | ||
| _ => false | ||
| }; | ||
| } | ||
|
|
||
| if (TryGetBooleanValue(out var booleanValue)) | ||
| { | ||
| return booleanValue == IsTruthyPropertyValue(overrideValue); | ||
|
|
@@ -205,6 +228,13 @@ public bool IsExactMatch(object? overrideValue) | |
| }; | ||
| } | ||
|
|
||
| static string StringifyDecimal(decimal value) | ||
| { | ||
| // Preserve the wire number's integer/float distinction and normalize its scale and precision like JSON filters. | ||
| using var document = JsonDocument.Parse(JsonSerializer.Serialize(value)); | ||
| return StringifyJsonElement(document.RootElement); | ||
|
Comment on lines
+233
to
+235
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/PostHog/Json/PropertyFilterValue.cs
Line: 233-235
Comment:
**Large decimals lose precision**
`StringifyDecimal` reparses the serialized number through `StringifyJsonElement`, which converts values outside the 64-bit integer ranges to `double`. Distinct high-precision decimals near `decimal.MaxValue` can therefore collapse to the same string and incorrectly satisfy version-2 `exact` matching. The maximum-value test does not catch this because both operands undergo the same lossy conversion.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
| } | ||
|
|
||
| bool TryGetBooleanValue(out bool value) | ||
| { | ||
| if (BooleanValue is { } booleanValue) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version 2 applies
StringifyDecimalonly when the property itself is adecimal. A decimal nested in a CLR collection still uses the generic invariant conversion, so[1.00m]becomes"[1.00]"while the wire-equivalent JSON[1.00]becomes"[1.0]". As a result, localexactandis_notevaluations can return different flag values depending on whether the same property arrived as CLR objects or JSON.Prompt To Fix With AI