From c762946ed72eca6bb09079bd8da5b7ee632f487d Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 16 Jul 2014 05:46:33 -0400 Subject: [PATCH] unescape infohash in API --- http/api.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/http/api.go b/http/api.go index 62fc6e5..2dc9e65 100644 --- a/http/api.go +++ b/http/api.go @@ -8,6 +8,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "net/url" "github.com/julienschmidt/httprouter" @@ -30,7 +31,12 @@ func (t *Tracker) getTorrent(w http.ResponseWriter, r *http.Request, p httproute return http.StatusInternalServerError, err } - torrent, err := conn.FindTorrent(p.ByName("infohash")) + infohash, err := url.QueryUnescape(p.ByName("infohash")) + if err != nil { + return http.StatusNotFound, err + } + + torrent, err := conn.FindTorrent(infohash) if err == tracker.ErrTorrentDNE { return http.StatusNotFound, err } else if err != nil { @@ -77,7 +83,12 @@ func (t *Tracker) delTorrent(w http.ResponseWriter, r *http.Request, p httproute return http.StatusInternalServerError, err } - err = conn.DeleteTorrent(p.ByName("infohash")) + infohash, err := url.QueryUnescape(p.ByName("infohash")) + if err != nil { + return http.StatusNotFound, err + } + + err = conn.DeleteTorrent(infohash) if err == tracker.ErrTorrentDNE { return http.StatusNotFound, err } else if err != nil {