From a32259b1a1207566b2027b073dbc728a80adf518 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Wed, 25 Jan 2017 18:59:06 +0300 Subject: [PATCH] src/telegram: Consider stream.path could not be parsed --- src/telegram.js | 4 +++- test/telegram.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/telegram.js b/src/telegram.js index f454c27..8f6af71 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -195,7 +195,9 @@ class TelegramBot extends EventEmitter { let fileName; let fileId; if (data instanceof stream.Stream) { - fileName = URL.parse(path.basename(data.path.toString())).pathname; + // Will be 'null' if could not be parsed. Default to 'filename'. + // For example, 'data.path' === '/?id=123' from 'request("https://example.com/?id=123")' + fileName = URL.parse(path.basename(data.path.toString())).pathname || 'filename'; formData = {}; formData[type] = { value: data, diff --git a/test/telegram.js b/test/telegram.js index 40c5ad5..b2c6059 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -991,5 +991,10 @@ describe('TelegramBot', function telegramSuite() { assert.ok(err.response.body.indexOf('Bad Request') !== -1); }); }); + it('should allow stream.path that can not be parsed', function test() { + const stream = fs.createReadStream(`${__dirname}/data/photo.gif`); + stream.path = '/?id=123'; // for example, 'http://example.com/?id=666' + return bot.sendPhoto(USERID, stream); + }); }); }); // End Telegram