Skip to content

Commit

Permalink
Merge pull request #10 from evangelion1204/error-finding-similar-paths
Browse files Browse the repository at this point in the history
Fixed an issue with exact match and similar paths in find and remove
  • Loading branch information
evangelion1204 committed Jan 21, 2016
2 parents c316325 + 3d94506 commit 1b138e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radix-tree",
"version": "0.3.1",
"version": "0.3.2",
"description": "Node.js version of a radix tree usable for routers or url path based storage.",
"main": "index.js",
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class Tree {
let child = node.children[index]

if (child.type === Node.DEFAULT) {
if ( path[offset] === child.path[0] ) {
if ( path[offset] === child.path[0] && path.indexOf(child.path, offset) === offset ) {
node = child
offset += node.path.length

Expand Down Expand Up @@ -291,7 +291,7 @@ export class Tree {
let child = node.children[index]

if (child.type === Node.DEFAULT) {
if ( path[offset] === child.path[0] ) {
if ( path[offset] === child.path[0] && path.indexOf(child.path, offset) === offset ) {
node = child
offset += node.path.length

Expand Down
9 changes: 9 additions & 0 deletions test/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ describe('Tree', function() {
})


it('should also work with very similar paths', function () {
let instance = new Tree()

instance.add('/test1')

expect(instance.find('/test1')).to.be.ok
expect(instance.find('/test2')).to.be.not.ok
})

it('should return the node on exact match of the path', function () {
let instance = new Tree()

Expand Down

0 comments on commit 1b138e7

Please sign in to comment.