From ae0ad0f6174852a05844553ba08b6a002303fe95 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Oct 2019 16:07:36 +0100 Subject: [PATCH 1/3] Fix invalid xt value for magnets --- lib/torrent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/torrent.js b/lib/torrent.js index 77cf8988..adbbad88 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -196,7 +196,7 @@ class Torrent extends EventEmitter { let parsedTorrent try { parsedTorrent = parseTorrent(torrentId) } catch (err) {} - if (parsedTorrent) { + if (parsedTorrent && parsedTorrent.infoHash) { // Attempt to set infoHash property synchronously this.infoHash = parsedTorrent.infoHash this._debugId = parsedTorrent.infoHash.toString('hex').substring(0, 7) From acca5b9e9d07dfd27227a3bf92a730ccae87178b Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Oct 2019 16:43:25 +0100 Subject: [PATCH 2/3] Add test for non-bittorrent URNs --- test/client-add.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/client-add.js b/test/client-add.js index 07de4908..d27f20cb 100644 --- a/test/client-add.js +++ b/test/client-add.js @@ -205,3 +205,35 @@ test('client.add: invalid torrent id: short buffer', function (t) { client.add(Buffer.from('abc')) }) + +test('client.add: non-bittorrent URNs', function (t) { + const magnets = [ + 'magnet:?xt=urn:sha1:PDAQRAOQQRYS76MRZJ33LK4MMVZBDSCL', + 'magnet:?xt=urn:tree:tiger:IZZG2KNL4BKA7LYEKK5JAX6BQ27UV4QZKPL2JZQ', + 'magnet:?xt=urn:bitprint:QBMYI5FTYSFFSP7HJ37XALYNNVYLJE27.E6ITPBX6LSBBW34T3UGPIVJDNNJZIQOMP5WNEUI', + 'magnet:?xt=urn:ed2k:31D6CFE0D16AE931B73C59D7E0C089C0', + 'magnet:?xt=urn:aich:D6EUDGK2DBTBEZ2XVN3G6H4CINSTZD7M', + 'magnet:?xt=urn:kzhash:35759fdf77748ba01240b0d8901127bfaff929ed1849b9283f7694b37c192d038f535434', + 'magnet:?xt=urn:md5:4e7bef74677be349ccffc6a178e38299' + ] + + t.plan(magnets.length * 2 + 1) + + var done = 0 + var client = new WebTorrent({ dht: false, tracker: false }) + + client.on('error', function (err) { + t.ok(err instanceof Error) + t.ok(err.message.indexOf('Invalid torrent identifier') >= 0) + + done += 1 + + if (done === magnets.length) client.destroy(function (err) { t.error(err, 'client destroyed') }) + }) + client.on('warning', function (err) { t.fail(err) }) + + // Non-bittorrent URNs (examples from Wikipedia) + magnets.forEach(function (magnet) { + client.add(magnet) + }) +}) From 250d3d7d03548281c93ebe09ca4b3dcb4c6d2fd7 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 28 Oct 2019 16:58:36 +0100 Subject: [PATCH 3/3] Move comment --- test/client-add.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/client-add.js b/test/client-add.js index d27f20cb..5372d9b3 100644 --- a/test/client-add.js +++ b/test/client-add.js @@ -207,6 +207,7 @@ test('client.add: invalid torrent id: short buffer', function (t) { }) test('client.add: non-bittorrent URNs', function (t) { + // Non-bittorrent URNs (examples from Wikipedia) const magnets = [ 'magnet:?xt=urn:sha1:PDAQRAOQQRYS76MRZJ33LK4MMVZBDSCL', 'magnet:?xt=urn:tree:tiger:IZZG2KNL4BKA7LYEKK5JAX6BQ27UV4QZKPL2JZQ', @@ -227,12 +228,10 @@ test('client.add: non-bittorrent URNs', function (t) { t.ok(err.message.indexOf('Invalid torrent identifier') >= 0) done += 1 - if (done === magnets.length) client.destroy(function (err) { t.error(err, 'client destroyed') }) }) client.on('warning', function (err) { t.fail(err) }) - // Non-bittorrent URNs (examples from Wikipedia) magnets.forEach(function (magnet) { client.add(magnet) })