diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0463213..bd6430e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - '*' permissions: - id-token: write # Required for OIDC + id-token: write # Required for OIDC contents: read jobs: diff --git a/.gitmodules b/.gitmodules index 93de146..b5ddcdf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "tests/engine/engine-tests/engine-test-data"] path = tests/engine/engine-tests/engine-test-data url = git@github.com:Flagsmith/engine-test-data.git - branch = v3.1.0 + branch = v3.4.1 diff --git a/flagsmith-engine/index.ts b/flagsmith-engine/index.ts index e3f20f1..03b8434 100644 --- a/flagsmith-engine/index.ts +++ b/flagsmith-engine/index.ts @@ -70,7 +70,7 @@ export function evaluateSegments(context: EvaluationContextWithMetadata): { } } : {}) - })); + })) as EvaluationResultSegments; const segmentOverrides = processSegmentOverrides(identitySegments); return { segments, segmentOverrides }; @@ -127,11 +127,11 @@ export function evaluateFeatures( for (const feature of Object.values(context.features || {})) { const segmentOverride = segmentOverrides[feature.name]; const finalFeature = segmentOverride ? segmentOverride.feature : feature; - const hasOverride = !!segmentOverride; - const { value: evaluatedValue, reason: evaluatedReason } = hasOverride - ? { value: finalFeature.value, reason: undefined } - : evaluateFeatureValue(finalFeature, getIdentityKey(context)); + const { value: evaluatedValue, reason: evaluatedReason } = evaluateFeatureValue( + finalFeature, + getIdentityKey(context) + ); flags[finalFeature.name] = { name: finalFeature.name, diff --git a/flagsmith-engine/segments/evaluators.ts b/flagsmith-engine/segments/evaluators.ts index aecae7f..1763481 100644 --- a/flagsmith-engine/segments/evaluators.ts +++ b/flagsmith-engine/segments/evaluators.ts @@ -131,22 +131,22 @@ function evaluateRuleConditions(ruleType: string, conditionResults: boolean[]): function getTraitValue(property: string, context?: GenericEvaluationContext): any { if (property.startsWith('$.')) { const contextValue = getContextValue(property, context); - if (contextValue && !isNonPrimitive(contextValue)) { + if (contextValue !== undefined && isPrimitive(contextValue)) { return contextValue; } } - const traits = context?.identity?.traits || {}; + return traits[property]; } -function isNonPrimitive(value: any): boolean { +function isPrimitive(value: any): boolean { if (value === null || value === undefined) { - return false; + return true; } // Objects and arrays are non-primitive - return typeof value === 'object'; + return typeof value !== 'object'; } /** @@ -167,7 +167,8 @@ export function getContextValue(jsonPath: string, context?: GenericEvaluationCon if (!context || !jsonPath?.startsWith('$.')) return undefined; try { - const results = jsonpath.query(context, jsonPath); + const normalizedPath = normalizeJsonPath(jsonPath); + const results = jsonpath.query(context, normalizedPath); return results.length > 0 ? results[0] : undefined; } catch (error) { return undefined; @@ -179,3 +180,7 @@ export function getIdentityKey(context?: GenericEvaluationContext): string | und return context.identity.key || `${context.environment.key}_${context.identity.identifier}`; } + +function normalizeJsonPath(jsonPath: string): string { + return jsonPath.replace(/\.([^.\[\]]+)$/, "['$1']"); +} diff --git a/tests/engine/engine-tests/engine-test-data b/tests/engine/engine-tests/engine-test-data index 6ab57ec..839e8d5 160000 --- a/tests/engine/engine-tests/engine-test-data +++ b/tests/engine/engine-tests/engine-test-data @@ -1 +1 @@ -Subproject commit 6ab57ec67bc84659e8b5aa41534b04fe45cc4cbe +Subproject commit 839e8d5e5f2e9af6392062cf5e575d43c03770d4