]> Sergey Matveev's repositories - btrtrc.git/blobdiff - tracker/http/http.go
Fix http announce of infohash containing ' ' bytes (#591)
[btrtrc.git] / tracker / http / http.go
index 15306ca974eaa0656318ab4eab533dbd9ad4f35c..f45cc7c2e6ec2f17f4702c11acc215e3493d4c9d 100644 (file)
@@ -11,6 +11,7 @@ import (
        "net/http"
        "net/url"
        "strconv"
+       "strings"
 
        "github.com/anacrolix/missinggo/httptoo"
        "github.com/anacrolix/torrent/bencode"
@@ -61,7 +62,9 @@ func setAnnounceParams(_url *url.URL, ar *AnnounceRequest, opts AnnounceOpt) {
        }
        doIp("ipv4", opts.ClientIp4)
        doIp("ipv6", opts.ClientIp6)
-       _url.RawQuery = q.Encode()
+       // We're operating purely on query-escaped strings, where + would have already been encoded to
+       // %2B, and + has no other special meaning. See https://github.com/anacrolix/torrent/issues/534.
+       _url.RawQuery = strings.ReplaceAll(q.Encode(), "+", "%20")
 }
 
 type AnnounceOpt struct {