Skip to content

Commit 17807dc

Browse files
authored
Merge pull request webtorrent#168 from feross/fix-167
Fix Client.scrape returns no error on invalid URL
2 parents a59a306 + 59bba81 commit 17807dc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Client.scrape = function (opts, cb) {
138138

139139
var client = new Client(clientOpts)
140140
client.once('error', cb)
141+
client.once('warning', cb)
141142

142143
var len = Array.isArray(opts.infoHash) ? opts.infoHash.length : 1
143144
var results = {}

test/scrape.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ test('ws: scrape using Client.scrape static method', function (t) {
8585
clientScrapeStatic(t, 'ws')
8686
})
8787

88+
// Ensure the callback function gets called when an invalid url is passed
89+
function clientScrapeStaticInvalid (t, serverType) {
90+
var announceUrl = serverType + '://invalid.lol'
91+
if (serverType === 'http') announceUrl += '/announce'
92+
93+
var client = Client.scrape({
94+
announce: announceUrl,
95+
infoHash: fixtures.leaves.parsedTorrent.infoHash,
96+
wrtc: {}
97+
}, function (err, data) {
98+
t.ok(err instanceof Error)
99+
t.end()
100+
})
101+
if (serverType === 'ws') common.mockWebsocketTracker(client)
102+
}
103+
104+
test.only('http: scrape using Client.scrape static method (invalid url)', function (t) {
105+
clientScrapeStaticInvalid(t, 'http')
106+
})
107+
108+
test('udp: scrape using Client.scrape static method (invalid url)', function (t) {
109+
clientScrapeStaticInvalid(t, 'udp')
110+
})
111+
112+
test('ws: scrape using Client.scrape static method (invalid url)', function (t) {
113+
clientScrapeStaticInvalid(t, 'ws')
114+
})
115+
88116
function clientScrapeMulti (t, serverType) {
89117
var infoHash1 = fixtures.leaves.parsedTorrent.infoHash
90118
var infoHash2 = fixtures.alice.parsedTorrent.infoHash

0 commit comments

Comments
 (0)