Skip to content

[4.x] Do not read missing nested getArray() keys from the top-level input - #57

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-getarray-missing-nested-key
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-getarray-missing-nested-key

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

For a nested filter map, Input::getArray() recurses with $datasource[$k] without checking that the key exists (and with $this->get($k, null, 'array') on the first level, which returns null for a missing key). A null data source switches getArray() back to reading the top-level input, so:

  • (new Input(['b' => '5']))->getArray(['a' => ['b' => 'int']]) returns ['a' => ['b' => 5]]: the missing a[b] is filled from the unrelated top-level b;
  • getArray(['a' => ['b' => 'int']], ['x' => 1]) additionally raises Warning: Undefined array key "a";
  • getArray(['a' => []]) with a missing returns the whole input under a.

The recursion now always passes an array ([] for a missing key), so it stays in explicit-datasource mode and missing nested fields come back as null run through the requested filter, like missing top-level fields in that mode.

#38 reports the same warning; its fix ($datasource[$k] ?? null) silences the warning but still recurses with null and therefore keeps reading from the top-level input. It also targets 2.x-dev.

Testing Instructions

New tests in InputTest: testGetArrayWithMissingNestedKey() and testGetArrayWithMissingNestedKeyAndEmptyMap() (real InputFilter). Both fail before the change and pass after it.

Documentation Changes Required

docs/overview.md ("Reading several values at once"): the note that nested keys must exist is replaced by the actual behaviour for missing keys.

Supersedes #38

🤖 Generated with Claude Code

For a nested filter map, getArray() recursed with $datasource[$k] without
checking the key, which raised an "Undefined array key" warning and passed
null on. A null data source switches getArray() back to the top-level
input, so a missing nested field was filled from an unrelated top-level
variable with the same name, and an empty nested map returned the whole
input. Recurse with an empty array instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant