Skip to content

Commit

Permalink
Use PathUnescape on Go 1.8+ (#57)
Browse files Browse the repository at this point in the history
Use PathUnescape on Go 1.8+

See PR #56 for the inspiration.
  • Loading branch information
dimfeld authored Oct 11, 2017
1 parent a5cfd3e commit 8cc36ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httptreemux

import (
"fmt"
"net/url"
"strings"
)

Expand Down Expand Up @@ -278,7 +277,7 @@ func (n *node) search(method, path string) (found *node, handler HandlerFunc, pa
if len(thisToken) > 0 { // Don't match on empty tokens.
wcNode, wcHandler, wcParams := n.wildcardChild.search(method, nextToken)
if wcHandler != nil || (found == nil && wcNode != nil) {
unescaped, err := url.QueryUnescape(thisToken)
unescaped, err := unescape(thisToken)
if err != nil {
unescaped = thisToken
}
Expand Down Expand Up @@ -311,7 +310,7 @@ func (n *node) search(method, path string) (found *node, handler HandlerFunc, pa
// Found a handler, or we found a catchall node without a handler.
// Either way, return it since there's nothing left to check after this.
if handler != nil || found == nil {
unescaped, err := url.QueryUnescape(path)
unescaped, err := unescape(path)
if err != nil {
unescaped = path
}
Expand Down
9 changes: 9 additions & 0 deletions unescape_17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !go1.8

package httptreemux

import "net/url"

func unescape(path string) (string, error) {
return url.QueryUnescape(path)
}
9 changes: 9 additions & 0 deletions unescape_18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build go1.8

package httptreemux

import "net/url"

func unescape(path string) (string, error) {
return url.PathUnescape(path)
}

0 comments on commit 8cc36ee

Please sign in to comment.