Skip to content

Commit 7988dc1

Browse files
committed
tree: fix panic in non-ascii routes
http://golang.org/ref/spec#Conversions_to_and_from_a_string_type string(0xce) == "\xc3\x8e" string([]byte{0xce}) == "\xce" Example: http://play.golang.org/p/nVEixeJjHS
1 parent f88e0d3 commit 7988dc1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

tree.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (n *node) addRoute(path string, handle Handle) {
118118
}
119119

120120
n.children = []*node{&child}
121-
n.indices = string(n.path[i])
121+
n.indices = string([]byte{n.path[i]})
122122
n.path = path[:i]
123123
n.handle = nil
124124
n.wildChild = false
@@ -169,7 +169,7 @@ func (n *node) addRoute(path string, handle Handle) {
169169

170170
// Otherwise insert it
171171
if c != ':' && c != '*' {
172-
n.indices += string(c)
172+
n.indices += string([]byte{c})
173173
child := &node{
174174
maxParams: numParams,
175175
}

tree_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ func TestTreeAddAndGet(t *testing.T) {
125125
"/doc/",
126126
"/doc/go_faq.html",
127127
"/doc/go1.html",
128+
"/α",
129+
"/β",
128130
}
129131
for _, route := range routes {
130132
tree.addRoute(route, fakeHandler(route))
@@ -142,6 +144,8 @@ func TestTreeAddAndGet(t *testing.T) {
142144
{"/cona", true, "", nil}, // key mismatch
143145
{"/no", true, "", nil}, // no matching child
144146
{"/ab", false, "/ab", nil},
147+
{"/α", false, "/α", nil},
148+
{"/β", false, "/β", nil},
145149
})
146150

147151
checkPriorities(t, tree)

0 commit comments

Comments
 (0)