Skip to content

Commit 7d82649

Browse files
authored
fix(flagd): improve targeting key check in fractional operator (open-feature#1048)
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
1 parent 00c9e87 commit 7d82649

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

libs/shared/flagd-core/src/lib/targeting/fractional.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export function fractionalFactory(logger: Logger) {
2929
bucketBy = args[0];
3030
buckets = args.slice(1, args.length);
3131
} else {
32-
bucketBy = `${flagdProperties[flagKeyPropertyKey]}${context[targetingPropertyKey]}`;
33-
if (!bucketBy) {
32+
const targetingKey = context[targetingPropertyKey];
33+
if (!targetingKey) {
3434
logger.debug('Missing targetingKey property, cannot perform fractional targeting');
3535
return null;
3636
}
37-
37+
bucketBy = `${flagdProperties[flagKeyPropertyKey]}${targetingKey}`;
3838
buckets = args;
3939
}
4040

libs/shared/flagd-core/src/lib/targeting/targeting.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ describe('fractional operator', () => {
187187

188188
expect(targeting.applyTargeting('flagA', input, { targetingKey: 'bucketKeyB' })).toBe('blue');
189189
});
190+
191+
it('should return null if targeting key is missing', () => {
192+
const input = {
193+
fractional: [
194+
['red', 1],
195+
['blue', 1],
196+
],
197+
};
198+
199+
expect(targeting.applyTargeting('flagA', input, {})).toBe(null);
200+
});
190201
});
191202

192203
describe('fractional operator should validate', () => {

0 commit comments

Comments
 (0)