Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '*'

permissions:
id-token: write # Required for OIDC
id-token: write # Required for OIDC
contents: read

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions flagsmith-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function evaluateSegments(context: EvaluationContextWithMetadata): {
}
}
: {})
}));
})) as EvaluationResultSegments;
const segmentOverrides = processSegmentOverrides(identitySegments);

return { segments, segmentOverrides };
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions flagsmith-engine/segments/evaluators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand All @@ -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;
Expand All @@ -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']");
}
2 changes: 1 addition & 1 deletion tests/engine/engine-tests/engine-test-data
Submodule engine-test-data updated 106 files