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) {