Commits

Constantin Veretennicov committed e071522

Fixed decoding bug: info_hashes were percent-decoded twice.

Comments (0)

Files changed (2)

       # most probably someone opened announce url in browser
       self.redirect('/')
     request_params = dict(
-      (name, urllib.unquote_plus(values[-1]))
+      (name, values[-1])
       for (name, values) in cgi.parse_qs(self.request.query_string).items())
     logging.debug(pprint.pformat(request_params))
     response_body = process_announce_request(
+import sys, os
+sys.path.append(os.path.join(os.path.dirname(__file__), '../app'))
+
+import util, main, models, webtest
+from nose.tools import *
+
+
+def setup():
+  global app
+  util.clear_datastore()
+  util.clear_memcache()
+  app = webtest.TestApp(main.create_application())
+
+
+@with_setup(util.clear_datastore)
+@with_setup(util.clear_memcache)
+def test_info_hash_with_percents_is_parsed_correctly():
+
+  app.get(
+    "/announce"
+    "?info_hash=%C9CM%14%25b8%17%85%8E%8A6%C9H%A9%D7'Z%97%0A"
+    "&peer_id=-UT1830-%8A%3E_%B8))%f8%Cf%C2wf%14"
+    "&port=17021&uploaded=0&downloaded=82162626&left=0&corrupt=0"
+    "&key=3CB7076D&numwant=200&compact=1&no_peer_id=1"
+    "&ip=0.0.0.0")
+
+  t = list(models.Torrent.all())
+  assert_equals(len(t), 1)
+  assert_equals(
+    t[0].info_hash, "\xc9CM\x14%b8\x17\x85\x8e\x8a6\xc9H\xa9\xd7'Z\x97\n")