From fc5a3284fe8a562ab7bf7c29b972a961591402fa Mon Sep 17 00:00:00 2001 From: Patchy Date: Wed, 8 Feb 2017 14:52:25 +1100 Subject: [PATCH] Check for invalid node values on delete --- src/Storage/DbalNestedSet.php | 3 +++ tests/Functional/DbalNestedSetTest.php | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Storage/DbalNestedSet.php b/src/Storage/DbalNestedSet.php index 370ff37d..cfe12c34 100644 --- a/src/Storage/DbalNestedSet.php +++ b/src/Storage/DbalNestedSet.php @@ -230,6 +230,9 @@ public function getTree() { * {@inheritdoc} */ public function deleteNode(Node $node) { + if ($node->getLeft() < 1 || $node->getRight() < 1) { + throw new \InvalidArgumentException("Left and right values must be > 0"); + } $left = $node->getLeft(); $right = $node->getRight(); $width = $right - $left + 1; diff --git a/tests/Functional/DbalNestedSetTest.php b/tests/Functional/DbalNestedSetTest.php index f2f93f09..e544e882 100644 --- a/tests/Functional/DbalNestedSetTest.php +++ b/tests/Functional/DbalNestedSetTest.php @@ -281,6 +281,16 @@ public function testDeleteNode() { $tree = $this->nestedSet->getTree(); } + /** + * Tests deleting a node with missing values. + * + * @expectedException \InvalidArgumentException + */ + public function testDeleteNodeInvalid() { + $node = new Node(1, 1); + $this->nestedSet->deleteNode($node); + } + /** * Tests deleting a node and its sub-tree. */