From b316d3afeb28e8f99f00a164b27f556d6f8485ea Mon Sep 17 00:00:00 2001 From: Ufuk Altinok Date: Wed, 28 Jan 2015 13:40:15 +0200 Subject: [PATCH] Handle empty url-list correctly (BEP19) Commit amended by Feross Aboukhadijeh --- index.js | 6 ++++++ test/empty-url-list.js | 11 +++++++++++ test/torrents/leaves-empty-url-list.torrent | Bin 0 -> 1854 bytes 3 files changed, 17 insertions(+) create mode 100644 test/empty-url-list.js create mode 100644 test/torrents/leaves-empty-url-list.torrent diff --git a/index.js b/index.js index f5e0387..48387c1 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,12 @@ function decodeTorrentFile (torrent) { result.announce = [].concat.apply([], result.announceList) // handle url-list (BEP19 / web seeding) + if (Buffer.isBuffer(torrent['url-list'])) { + // some clients set url-list to empty string + torrent['url-list'] = torrent['url-list'].length > 0 + ? [ torrent['url-list'] ] + : [] + } result.urlList = (torrent['url-list'] || []).map(function (url) { return url.toString() }) diff --git a/test/empty-url-list.js b/test/empty-url-list.js new file mode 100644 index 0000000..a8bea33 --- /dev/null +++ b/test/empty-url-list.js @@ -0,0 +1,11 @@ +var fs = require('fs') +var parseTorrent = require('../') +var test = require('tape') + +var leavesUrlList = fs.readFileSync(__dirname + '/torrents/leaves-empty-url-list.torrent') + +test('parse empty url-list', function (t) { + var torrent = parseTorrent(leavesUrlList) + t.deepEqual(torrent.urlList, []) + t.end() +}) diff --git a/test/torrents/leaves-empty-url-list.torrent b/test/torrents/leaves-empty-url-list.torrent new file mode 100644 index 0000000000000000000000000000000000000000..d6c2d8b2a6521f2d00eb57bfb8c6baeef551d635 GIT binary patch literal 1854 zcma)-X*kr20>(olWZx!Bg=}HQ%$S+R*fZvKQW-)yCC2yKp>8Cq94G5(8&-lCXvNL2N**co@6)z%b)-xK&T|6S*cVmcFDMA_FhRzjEgx&swG$J>fJe+Mu|Tr`5L^phbhI zkc^ZF&%wXT{v3(j`M^6ZrC|=aR1|bgg#-T9UX=B+&Qy4v`HkqROjmV3 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