Skip to content

fix: Reject "multi" as the kind of an individual context#272

Open
kinyoklion wants to merge 1 commit into
mainfrom
rlamb/sdk-2383/reject-multi-kind
Open

fix: Reject "multi" as the kind of an individual context#272
kinyoklion wants to merge 1 commit into
mainfrom
rlamb/sdk-2383/reject-multi-kind

Conversation

@kinyoklion
Copy link
Copy Markdown
Member

@kinyoklion kinyoklion commented May 20, 2026

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.

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

  • flutter test test/ld_context_test.dart — 36 tests pass (new + existing)
  • flutter test (full common package) — 437 tests pass
  • dart analyze --fatal-infos lib test — no issues
  • dart format — no changes
  • Manual: LDContextBuilder().kind('multi', 'alice').build().valid is now false; previously true
  • Manual: a multi-context that includes a "multi" sub-kind builds as invalid

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.

Reviewed by Cursor Bugbot for commit a2abb8f. Bugbot is set up for automated code reviews on this repo. Configure here.

The "multi" kind string is reserved as the discriminator for the
multi-context wrapper. An individual context must not use it. The
internal _validKind helper 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.

Extends the existing invalid-kinds group with the single-kind case and
adds a separate test for the multi-context case (which exercises the
"any sub-kind invalid → whole context invalid" path).
@kinyoklion kinyoklion requested a review from a team as a code owner May 20, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants