Skip to content

Commit efd938b

Browse files
committed
Fix issue with TrieNode when value is ending with same string.
1 parent ba0b0b6 commit efd938b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

spec/drupol/phptree/Node/TrieNodeSpec.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public function it_can_add_node()
2020
$this->beConstructedWith('root', 'root');
2121

2222
$nodes = [
23+
1000,
24+
1001,
25+
10011,
26+
2000,
27+
2001,
28+
20011,
2329
'ab',
2430
'abc',
2531
'abcd',
@@ -31,12 +37,12 @@ public function it_can_add_node()
3137
];
3238

3339
foreach ($nodes as $key => $value) {
34-
$nodes[$key] = new KeyValueNode($key, $value);
40+
$nodes[$key] = new KeyValueNode($key, (string) $value);
3541
}
3642

3743
$this
3844
->add(...$nodes)
3945
->count()
40-
->shouldReturn(25);
46+
->shouldReturn(43);
4147
}
4248
}

src/Node/TrieNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function add(NodeInterface ...$nodes): NodeInterface
2323
$parent = $this->append($node);
2424

2525
$dataWithoutFirstLetter = \substr($data, 1);
26-
if (!empty($dataWithoutFirstLetter)) {
26+
if ($dataWithoutFirstLetter > '') {
2727
$parent->add(new TrieNode($hash, $dataWithoutFirstLetter));
2828
} else {
2929
$nodes = [$node->getValue()];

0 commit comments

Comments
 (0)