From 30401df4b7ad5fc0bf201ed8294303930a7e7fbe Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 2 Dec 2020 10:37:51 +0200 Subject: [PATCH] Fixed Flex ordering to be natural and case insensitive --- CHANGELOG.md | 1 + system/src/Grav/Framework/Flex/FlexCollection.php | 4 +--- system/src/Grav/Framework/Flex/FlexIndex.php | 6 +++--- system/src/Grav/Framework/Flex/Storage/FileStorage.php | 2 +- system/src/Grav/Framework/Flex/Storage/FolderStorage.php | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a4a70e12..0cfce60b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ * Fixed `|safe_email` filter to return safe and escaped UTF-8 HTML [#3072](https://github.com/getgrav/grav/issues/3072) * Fixed exception in CLI GPM and backup commands when `php-zip` is not enabled [#3075](https://github.com/getgrav/grav/issues/3075) * Fix for XSS advisory [GHSA-cvmr-6428-87w9](https://github.com/getgrav/grav/security/advisories/GHSA-cvmr-6428-87w9) + * Fixed Flex ordering to be natural and case insensitive [flex-objects#87](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/87) # v1.7.0-rc.17 ## 10/07/2020 diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index 8bd2e6d65..26e20573c 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -144,9 +144,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface $matching = array_filter($matching); if ($matching) { - uksort($matching, static function ($a, $b) { - return -($a <=> $b); - }); + arsort($matching, SORT_NUMERIC); } return $this->select(array_keys($matching)); diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index c716472a9..f9ef00113 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -389,9 +389,9 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde // Order by current field. if (strtoupper($ordering) === 'DESC') { - arsort($search, SORT_NATURAL); + arsort($search, SORT_NATURAL | SORT_FLAG_CASE); } else { - asort($search, SORT_NATURAL); + asort($search, SORT_NATURAL | SORT_FLAG_CASE); } $previous = $search; @@ -738,7 +738,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde } // Sort the index before saving it. - ksort($index, SORT_NATURAL); + ksort($index, SORT_NATURAL | SORT_FLAG_CASE); static::onChanges($index, $added, $updated, $removed); diff --git a/system/src/Grav/Framework/Flex/Storage/FileStorage.php b/system/src/Grav/Framework/Flex/Storage/FileStorage.php index 7a4546e1b..b854555eb 100644 --- a/system/src/Grav/Framework/Flex/Storage/FileStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/FileStorage.php @@ -82,7 +82,7 @@ class FileStorage extends FolderStorage $list[$key] = $this->getObjectMeta($key); } - ksort($list, SORT_NATURAL); + ksort($list, SORT_NATURAL | SORT_FLAG_CASE); return $list; } diff --git a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php index 9cd43faa7..8e77c5e63 100644 --- a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php @@ -553,7 +553,7 @@ class FolderStorage extends AbstractFilesystemStorage $list = $this->buildIndexFromFilesystem($path); } - ksort($list, SORT_NATURAL); + ksort($list, SORT_NATURAL | SORT_FLAG_CASE); return $list; }