From 538bb3e20a0d1861d5adfcfdbf3f98abd2c5ff3a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 17 Dec 2014 21:17:58 -0800 Subject: [PATCH 1/2] include additional debug information --- client.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client.js b/client.js index af543af..27703ee 100644 --- a/client.js +++ b/client.js @@ -454,14 +454,18 @@ Tracker.prototype._handleResponse = function (requestUrl, data) { } var failure = data['failure reason'] if (failure) { + debug('failure from ' + requestUrl + ' (' + failure + ')') return self.client.emit('warning', new Error(failure)) } var warning = data['warning message'] if (warning) { + debug('warning from ' + requestUrl + ' (' + warning + ')') self.client.emit('warning', new Error(warning)) } + debug('response from ' + requestUrl) + if (requestUrl === self._announceUrl) { var interval = data.interval || data['min interval'] if (interval && !self._opts.interval && self._intervalMs !== 0) { From 69211515c2ca62af0826c09d8289a16cd7437a9a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 17 Dec 2014 21:18:46 -0800 Subject: [PATCH 2/2] encode special characters @*/+ in http tracker urls Fixes https://github.com/feross/webtorrent/issues/196 --- lib/common.js | 4 ++++ test/querystring.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/querystring.js diff --git a/lib/common.js b/lib/common.js index 1e2b792..9d8939d 100644 --- a/lib/common.js +++ b/lib/common.js @@ -59,6 +59,10 @@ exports.querystringStringify = function (obj) { var saved = querystring.escape querystring.escape = escape // global var ret = querystring.stringify(obj) + ret = ret.replace(/[\@\*\/\+]/g, function (char) { + // `escape` doesn't encode the characters @*/+ so we do it manually + return '%' + char.charCodeAt(0).toString(16).toUpperCase() + }) querystring.escape = saved return ret } diff --git a/test/querystring.js b/test/querystring.js new file mode 100644 index 0000000..cf9d33d --- /dev/null +++ b/test/querystring.js @@ -0,0 +1,16 @@ +var common = require('../lib/common') +var test = require('tape') + +// https://github.com/feross/webtorrent/issues/196 +test('encode special chars +* in http tracker urls', function (t) { + var q = { + info_hash: new Buffer('a2a15537542b22925ad10486bf7a8b2a9c42f0d1', 'hex').toString('binary') + } + var encoded = 'info_hash=%A2%A1U7T%2B%22%92Z%D1%04%86%BFz%8B%2A%9CB%F0%D1' + t.equal(common.querystringStringify(q), encoded) + + // sanity check that encode-decode matches up + t.deepEqual(common.querystringParse(common.querystringStringify(q)), q) + + t.end() +})