Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsed torrent #1770

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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)
@@ -205,3 +205,34 @@ test('client.add: invalid torrent id: short buffer', function (t) {

client.add(Buffer.from('abc'))
})

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',
'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) })

magnets.forEach(function (magnet) {
client.add(magnet)
})
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.