Commit f46679a
authored
fix: Reject "multi" as the kind of an individual context (#272)
Refs SDK-2383.
## Summary
The string `"multi"` is reserved as the LaunchDarkly multi-context
discriminator. An individual context must not use `"multi"` as its kind.
The internal `_validKind` helper in
`packages/common/lib/src/ld_context.dart` was only rejecting `"kind"`;
building with `.kind("multi", ...)` was producing a *valid* `LDContext`,
and a multi-context that included `"multi"` as one of its sub-kinds was
also valid.
```dart
bool _validKind(String kind) {
- return kind != 'kind' && _kindExp.hasMatch(kind);
+ return kind != 'kind' && kind != 'multi' && _kindExp.hasMatch(kind);
}
```
This propagates the kind validation Flutter SDK already implements for
`"kind"` to also cover `"multi"`. Both single-kind and multi-context
build paths run every sub-kind through `_validKind`, so a single change
covers both.
## Test plan
- [x] `flutter test test/ld_context_test.dart` — 36 tests pass (new +
existing)
- [x] `flutter test` (full common package) — 437 tests pass
- [x] `dart analyze --fatal-infos lib test` — no issues
- [x] `dart format` — no changes
- [x] Manual: `LDContextBuilder().kind('multi', 'alice').build().valid`
is now `false`; previously `true`
- [x] Manual: a multi-context that includes a `"multi"` sub-kind builds
as invalid
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: a small validation tightening that only changes behavior for
previously-accepted invalid input (kind == "multi"). Main risk is
backward incompatibility for callers incorrectly using "multi" as a
kind, now producing invalid contexts.
>
> **Overview**
> Reserves `"multi"` by updating kind validation so an individual
context cannot use `kind == "multi"`, causing such contexts (and
multi-contexts that include a `"multi"` sub-kind) to build as invalid.
>
> Updates tests to treat `"multi"` as an invalid kind and adds coverage
ensuring invalid contexts return empty `canonicalKey` and `keys`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a2abb8f. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 74ee884 commit f46679a
2 files changed
Lines changed: 14 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
| |||
0 commit comments