From 8ccdae9c6579d6297b0f4e2ef6cd5432390d83c8 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 26 Jan 2017 12:04:25 +0100 Subject: [PATCH] Trie.remove(nonexistent-node) is a no-op --- lib/trie.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/trie.js b/lib/trie.js index 49e93d54..075379bd 100644 --- a/lib/trie.js +++ b/lib/trie.js @@ -75,6 +75,11 @@ URLTrie.prototype.remove = function (path) { } var part = path.shift(); var child = this.branches[part]; + if (child === undefined) { + // Requested node doesn't exist, + // consider it already removed. + return; + child.remove(path); if (child.size === 0 && child.data === undefined) { // child has no branches and is not a leaf