Skip to content

Commit daf885f

Browse files
authored
fix(core): feature flag values should be booleans (#21759)
`FeatureFlags.isEnabled()` returns `boolean | undefined`, but if the value of the feature flag is something other than a boolean, it will actually return that type instead. For example, ```ts node.setContext(someFeatureFlag, 'true'); const enabled = FeatureFlags.of(node).isEnabled(someFeatureFlag); if (enabled) { // will work } if (enabled === true) { // will not work because enabled === 'true' } ``` It looks like the only place this bug crops up is in the `FunctionVersionUpgrade` aspect. https://github.com/aws/aws-cdk/blob/8b0832334afee496355e7aeb684773d8f939f058/packages/@aws-cdk/aws-lambda/lib/function.ts#L1306 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent da61adc commit daf885f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/@aws-cdk/core/lib/feature-flags.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ export class FeatureFlags {
3232
}
3333
return true;
3434
}
35-
return context ?? cxapi.futureFlagDefault(featureFlag);
35+
return context !== undefined ? Boolean(context) : cxapi.futureFlagDefault(featureFlag);
3636
}
3737
}

packages/@aws-cdk/core/test/feature-flags.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,13 @@ describe('feature flags', () => {
2323

2424
expect(FeatureFlags.of(stack).isEnabled('non-existent-flag')).toEqual(false);
2525
});
26+
27+
test('strings are evaluated as boolean', () => {
28+
const stack = new Stack();
29+
stack.node.setContext(cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT, 'true');
30+
31+
const actual = FeatureFlags.of(stack).isEnabled(cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT);
32+
expect(actual).toEqual(true);
33+
});
2634
});
2735
});

0 commit comments

Comments
 (0)