Skip to content

Commit

Permalink
StringHelper::parseStr() missing decode value in case of variable s…
Browse files Browse the repository at this point in the history
…tarts with brackets
  • Loading branch information
ElGigi committed Mar 7, 2022
1 parent a9d8f12 commit 9cb5d1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
to [Semantic Versioning] (http://semver.org/). For change log format,
use [Keep a Changelog] (http://keepachangelog.com/).

## [1.6.5] - 2022-03-07

### Fixed

- `StringHelper::parseStr()` missing decode value in case of variable starts with brackets

## [1.6.4] - 2022-03-07

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ public static function parseStr(string $str, bool $keepDots = true): array
}

$result = reset($result);
$final = b_array_merge_recursive($final, [urldecode($split[0]) => $result ?: ($split[1] ?? null)]);
if (false === $result) {
$result = urldecode($split[1] ?? '');
}
$final = b_array_merge_recursive($final, [urldecode($split[0]) => $result]);
}

return $final;
Expand Down
4 changes: 2 additions & 2 deletions tests/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public function testParseStr()
StringHelper::parseStr('first=value&arr%5B%5D=foo+bar&arr%5b%5d=baz')
);
$this->assertEquals(
['[first]' => 'value', '[foo]' => 'bar', 'arr' => ['baz']],
StringHelper::parseStr('%5Bfirst%5D=value&%5Bfoo%5D=bar&arr%5b%5d=baz')
['[first]' => 'val[ue', '[foo]' => 'bar', 'arr' => ['baz']],
StringHelper::parseStr('%5Bfirst%5D=val%5Bue&%5Bfoo%5D=bar&arr%5b%5d=baz')
);

$this->assertEquals([], StringHelper::parseStr(''));
Expand Down

0 comments on commit 9cb5d1b

Please sign in to comment.