Skip to content
This repository has been archived by the owner on Apr 13, 2018. It is now read-only.

Commit

Permalink
Handle empty url-list correctly (BEP19)
Browse files Browse the repository at this point in the history
Commit amended by Feross Aboukhadijeh <feross@feross.org>
  • Loading branch information
ualtinok authored and feross committed Jan 30, 2015
1 parent d41930f commit b316d3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
11 changes: 11 additions & 0 deletions test/empty-url-list.js
Original file line number Diff line number Diff line change
@@ -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()
})
Binary file added test/torrents/leaves-empty-url-list.torrent
Binary file not shown.

0 comments on commit b316d3a

Please sign in to comment.