Skip to content

fix: Prefer a targeting key of "0" over the key attribute - #44

Merged
keelerm84 merged 2 commits into
launchdarkly:mainfrom
zigzagdev:fix/zero-targeting-key
Nov 23, 2026
Merged

keelerm84 merged 2 commits into
launchdarkly:mainfrom
zigzagdev:fix/zero-targeting-key

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

N/A

Describe the solution you've provided

The targeting key now takes precedence over the key attribute. It falls back to key only when the targeting key is null or "".

Reason

getTargetingKey() falls back to key with $targetingKey ?: $key. Since "0" is falsy in PHP, a targeting key of "0" is replaced by the key attribute.

For example:

new EvaluationContext("0", new Attributes(["key" => "abc"]))

In this case, the context key is abc instead of 0.

Describe alternatives you've considered

None

Additional context

Added tests for single-context and multi-kind context cases. Both fail without the fix.

PHPUnit 9.6.39 / PHP 8.2–8.5
OK (55 tests, 119 assertions)

Note

Overview
Fixes targeting key resolution in EvaluationContextConverter::getTargetingKey so a provided targetingKey of "0" is no longer treated as missing. The fallback to the attribute key now runs only when targetingKey is null or "", instead of relying on PHP’s falsy ?: behavior.

Adds tests for single- and multi-kind contexts confirming "0" wins over a conflicting attribute key.

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

getTargetingKey() used `$targetingKey ?: $key` to fall back to the key
attribute. "0" is falsy in PHP, so a targeting key of "0" was replaced
by the key attribute, even though the targeting key should take
precedence.

Fall back to the key attribute only when the targeting key is null or
an empty string, matching the check earlier in the same method.
…ribute

Add single-context and multi-kind context cases, since both go through
getTargetingKey().
@zigzagdev
zigzagdev requested a review from a team as a code owner November 22, 2026 11:39
@zigzagdev
zigzagdev marked this pull request as draft November 22, 2026 11:39
@zigzagdev zigzagdev changed the title Fix/zero targeting key fix: Prefer a targeting key of "0" over the key attribute Nov 22, 2026
@zigzagdev
zigzagdev marked this pull request as ready for review November 22, 2026 14:51
@keelerm84
keelerm84 merged commit 68554ef into launchdarkly:main Nov 23, 2026
15 of 18 checks passed
@keelerm84

Copy link
Copy Markdown
Member

Thank you @zigzagdev for this contribution!

@zigzagdev
zigzagdev deleted the fix/zero-targeting-key branch November 23, 2026 21:33
keelerm84 pushed a commit that referenced this pull request Nov 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.1.2](2.1.1...2.1.2)
(2026-11-23)


### Bug Fixes

* Prefer a targeting key of "0" over the key attribute
([#44](#44))
([68554ef](68554ef))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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