radix icon indicating copy to clipboard operation
radix copied to clipboard

dynamic path breaks when using multiple placeholder names in the same path

Open jakecoffman opened this issue 6 years ago • 0 comments

Here's a test that illustrates the issue. Since :page and :slug are different they seem to cause an issue and the node.Value becomes nil. One could argue "well then don't do that" but I'm taking in the tree config from users so I'd rather not have to try and sanitize this before hand.

func TestRadixTree(t *testing.T) {
	tree := radix.New(0)
	tree.Add("/test", 1)
	tree.Add("/test/:page", 2)
	tree.Add("/test/:slug/two", 3)
	tree.SetBoundaries(':', '/')
	tree.Sort(radix.PrioritySort)
	if node, _ := tree.Get("/test"); node == nil || node.Value != 1 {
		t.Errorf("Get /test failed %#v", node)
	}
	// errors: Value is nil
	if node, _ := tree.Get("/test/one"); node == nil || node.Value != 2 {
		t.Errorf("Get /test/one failed %#v", node)
	}
	// errors: node is nil
	if node, _ := tree.Get("/test/one/two"); node == nil || node.Value != 3 {
		t.Errorf("Get /test/one/two failed %#v", node)
	}
}

jakecoffman avatar Nov 21 '19 15:11 jakecoffman