diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-01-01 22:53:28 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-01-01 22:53:28 +0300 |
commit | b2ea3e43021d6a83036696128cb35cdc6ec4eb42 (patch) | |
tree | 8be0c0fd30c8c8de3a0361c6613755b627a16cbe | |
parent | d0cf21ca92747eab9a59aef78caa48f3a76d849f (diff) |
Throw error on client.add('')
-rw-r--r-- | lib/torrent.js | 2 | ||||
-rw-r--r-- | test/basic.js | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 8af4b68..d7257a7 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -90,7 +90,7 @@ function Torrent (torrentId, opts) { // for cleanup this._servers = [] - if (torrentId) this._onTorrentId(torrentId) + if (torrentId != null) this._onTorrentId(torrentId) } // Time remaining (in milliseconds) diff --git a/test/basic.js b/test/basic.js index 2630f04..26b543b 100644 --- a/test/basic.js +++ b/test/basic.js @@ -326,3 +326,20 @@ test('after client.destroy(), no "torrent" or "ready" events emitted', function client.destroy(function (err) { t.error(err, 'client destroyed') }) }) + +test('client.add: invalid torrent id: empty string', function (t) { + t.plan(3) + + 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) + + client.destroy(function (err) { t.error(err, 'client destroyed') }) + }) + client.on('warning', function (err) { t.fail(err) }) + + client.add('') +}) + |