Skip to content

Commit c37aac7

Browse files
committed
'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
1 parent 2c30582 commit c37aac7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

client.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const once = require('once')
55
const parallel = require('run-parallel')
66
const Peer = require('simple-peer')
77
const uniq = require('uniq')
8-
const url = require('url')
8+
const URL = require('url').URL
99

1010
const common = require('./lib/common')
1111
const HTTPTracker = require('./lib/client/http-tracker') // empty object in browser
@@ -85,7 +85,14 @@ class Client extends EventEmitter {
8585

8686
this._trackers = announce
8787
.map(announceUrl => {
88-
const parsedUrl = url.parse(announceUrl)
88+
let parsedUrl
89+
try {
90+
parsedUrl = new URL(announceUrl)
91+
} catch (err) {
92+
nextTickWarn(new Error(`Invalid tracker URL: ${announceUrl}`))
93+
return null
94+
}
95+
8996
const port = parsedUrl.port
9097
if (port < 0 || port > 65535) {
9198
nextTickWarn(new Error(`Invalid tracker port: ${announceUrl}`))

0 commit comments

Comments
 (0)