diff --git a/client.js b/client.js index a49bde5..f8888eb 100644 --- a/client.js +++ b/client.js @@ -5,7 +5,7 @@ const once = require('once') const parallel = require('run-parallel') const Peer = require('simple-peer') const uniq = require('uniq') -const url = require('url') +const URL = require('url').URL const common = require('./lib/common') const HTTPTracker = require('./lib/client/http-tracker') // empty object in browser @@ -85,7 +85,14 @@ class Client extends EventEmitter { this._trackers = announce .map(announceUrl => { - const parsedUrl = url.parse(announceUrl) + let parsedUrl + try { + parsedUrl = new URL(announceUrl) + } catch (err) { + nextTickWarn(new Error(`Invalid tracker URL: ${announceUrl}`)) + return null + } + const port = parsedUrl.port if (port < 0 || port > 65535) { nextTickWarn(new Error(`Invalid tracker port: ${announceUrl}`))