Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Global unique node names #9
While using RubyTree at work I noticed that the node names, though the documentation states "The node name is expected to be unique within the tree.", are not unique if you add an already added node/name to another child. There are several ways to fix this, the easiest implementation, is to check if the tree, where the child is added too, already contains a node with this name.
Because I'm not allowed to spend too much worktime on open source projects I stuck with the simple implementation I mentioned and hope that this is of any use to you anyway. While testing, the "add node to self as child" case was fixed too so I changed the test likewise.
Adding a node might still be exploitable by something like this, I hope you get the idea, could happen anytime you add a node or merge two trees:
@root = Tree::TreeNode.new('root', "Root node") @child1 = Tree::TreeNode.new('child1', '1st child') @child2 = Tree::TreeNode.new('child2', '2nd child') @conflict = Tree::TreeNode.new('conflict', 'Should do problems') @child1 << @conflict # should work because @conflict is not in root-tree @child2 << @conflict # same here. @root << @child1 # no problem so far @root << @child2 # now two nodes with the name 'conflict' exist in root tree
Thanks a lot for RubyTree and best regards, ysf :)