evolve75/RubyTree — pull request #9 by ysf (2012-08-23 09:35:22+00:00)
Title: Global unique node names

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:

```ruby
@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 :)