Fixed bug that sortByMany value is null when using SORT_NATURAL (#7124)

This commit is contained in:
guandeng 2024-10-23 18:12:23 +08:00 committed by GitHub
parent cc61a3602f
commit f6dabc8889
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -7,6 +7,10 @@
- [#7071](https://github.com/hyperf/hyperf/pull/7071) Added `Hyperf\Database\Schema\Blueprint::tinyText()`.
- [#7110](https://github.com/hyperf/hyperf/pull/7110) Added support for disallowing class morphs.
## Fixed
- [#7124](https://github.com/hyperf/hyperf/pull/7124) Fixed bug that `sortByMany` value is null when using `SORT_NATURAL`.
# v3.1.43 - 2024-10-10
## Fixed

View File

@ -1616,7 +1616,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
$result = match ($options) {
SORT_NUMERIC => intval($values[0]) <=> intval($values[1]),
SORT_STRING => strcmp($values[0], $values[1]),
SORT_NATURAL => strnatcmp($values[0], $values[1]),
SORT_NATURAL => strnatcmp((string) $values[0], (string) $values[1]),
SORT_LOCALE_STRING => strcoll($values[0], $values[1]),
default => $values[0] <=> $values[1],
};

View File

@ -1341,5 +1341,16 @@ class CollectionTest extends TestCase
'd' => ['id' => 4, 'name' => 'd'],
'e' => ['id' => 5, 'name' => 'e'],
]), (string) $dataMany);
$dataManyNull = (new $collection(
[
['id' => 2, 'name' => 'b'],
['id' => 1, 'name' => null],
]
))->sortBy([['id', 'desc'], ['name', 'desc']], SORT_NATURAL);
$this->assertEquals(json_encode([
['id' => 2, 'name' => 'b'],
['id' => 1, 'name' => null],
]), json_encode($dataManyNull));
}
}