From 5e26064ebe2366ee3c726a616e388f795bf480a3 Mon Sep 17 00:00:00 2001 From: Andrej Rypo Date: Fri, 19 Jan 2024 20:32:37 +0100 Subject: [PATCH] correct PHP < 8.2 issue with empty path string --- src/MaterializedPath/TreeBuilder.php | 2 +- tests/mptree.phpt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MaterializedPath/TreeBuilder.php b/src/MaterializedPath/TreeBuilder.php index 7a25d41..0356e28 100644 --- a/src/MaterializedPath/TreeBuilder.php +++ b/src/MaterializedPath/TreeBuilder.php @@ -71,7 +71,7 @@ public static function fixed(int $levelWidth, callable $accessor): callable { return function (mixed $data) use ($levelWidth, $accessor): array { $path = $accessor($data); - if (null === $path) { + if (null === $path || $path === '') { return []; } if (!is_string($path)) { diff --git a/tests/mptree.phpt b/tests/mptree.phpt index c2204e9..04aeb56 100644 --- a/tests/mptree.phpt +++ b/tests/mptree.phpt @@ -86,6 +86,7 @@ class Item ); Assert::same(['000', '000'], $vectorExtractor('000000')); Assert::same(['foo', 'bar'], $vectorExtractor('foobar')); + Assert::same(['x'], $vectorExtractor('x')); // shorter than 3 Assert::same([], $vectorExtractor('')); Assert::same([], $vectorExtractor(null)); Assert::throws(function () use ($vectorExtractor) {