Skip to content

Commit 8cc36ee

Browse files
authored
Use PathUnescape on Go 1.8+ (#57)
Use PathUnescape on Go 1.8+ See PR #56 for the inspiration.
1 parent a5cfd3e commit 8cc36ee

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

tree.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package httptreemux
22

33
import (
44
"fmt"
5-
"net/url"
65
"strings"
76
)
87

@@ -278,7 +277,7 @@ func (n *node) search(method, path string) (found *node, handler HandlerFunc, pa
278277
if len(thisToken) > 0 { // Don't match on empty tokens.
279278
wcNode, wcHandler, wcParams := n.wildcardChild.search(method, nextToken)
280279
if wcHandler != nil || (found == nil && wcNode != nil) {
281-
unescaped, err := url.QueryUnescape(thisToken)
280+
unescaped, err := unescape(thisToken)
282281
if err != nil {
283282
unescaped = thisToken
284283
}
@@ -311,7 +310,7 @@ func (n *node) search(method, path string) (found *node, handler HandlerFunc, pa
311310
// Found a handler, or we found a catchall node without a handler.
312311
// Either way, return it since there's nothing left to check after this.
313312
if handler != nil || found == nil {
314-
unescaped, err := url.QueryUnescape(path)
313+
unescaped, err := unescape(path)
315314
if err != nil {
316315
unescaped = path
317316
}

unescape_17.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build !go1.8
2+
3+
package httptreemux
4+
5+
import "net/url"
6+
7+
func unescape(path string) (string, error) {
8+
return url.QueryUnescape(path)
9+
}

unescape_18.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build go1.8
2+
3+
package httptreemux
4+
5+
import "net/url"
6+
7+
func unescape(path string) (string, error) {
8+
return url.PathUnescape(path)
9+
}

0 commit comments

Comments
 (0)