Skip to content

Commit 6a1543a

Browse files
authored
fix: restore deep dot-notation traversal in Language::getLine() (codeigniter4#10189)
1 parent e69dfca commit 6a1543a

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

system/Language/Language.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function getLine(string $line, array $args = [])
134134
}
135135

136136
/**
137-
* @return list<string>|string|null
137+
* @return array<array-key, mixed>|string|null
138138
*/
139139
protected function getTranslationOutput(string $locale, string $file, string $parsedLine)
140140
{
@@ -160,7 +160,7 @@ protected function getTranslationOutput(string $locale, string $file, string $pa
160160
}
161161
}
162162

163-
if ($output !== null && ! is_array($output)) {
163+
if ($output !== null) {
164164
return $output;
165165
}
166166
}

tests/system/Language/LanguageTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ public function testLanguageNestedArrayDefinition(): void
381381
$this->assertSame('e', $lang->getLine('Nested.a.b.c.d'));
382382
}
383383

384+
/**
385+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/10187
386+
*/
387+
public function testLanguageNestedArrayDefinitionReturnsIntermediateArrays(): void
388+
{
389+
$lang = new SecondMockLanguage('en');
390+
$lang->loadem('Nested', 'en');
391+
392+
$this->assertSame(['b' => ['c' => ['d' => 'e']]], $lang->getLine('Nested.a'));
393+
$this->assertSame(['c' => ['d' => 'e']], $lang->getLine('Nested.a.b'));
394+
$this->assertSame(['d' => 'e'], $lang->getLine('Nested.a.b.c'));
395+
}
396+
384397
public function testLanguageKeySeparatedByDot(): void
385398
{
386399
$lang = new SecondMockLanguage('en');

user_guide_src/source/changelogs/v4.7.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Bugs Fixed
4646
- **Database:** Fixed a bug where the PostgreSQL driver's ``increment()`` and ``decrement()`` methods were not working for numeric columns.
4747
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
4848
- **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets.
49+
- **Language:** Fixed a bug where ``Language::getLine()`` returned the literal dot-notation key instead of the nested array value when the requested key resolved to an intermediate array three or more levels deep.
4950
- **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger.
5051
- **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator.
5152
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.

0 commit comments

Comments
 (0)