mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-30 22:05:28 +00:00
src/telegram: Consider stream.path could not be parsed
This commit is contained in:
@@ -195,7 +195,9 @@ class TelegramBot extends EventEmitter {
|
|||||||
let fileName;
|
let fileName;
|
||||||
let fileId;
|
let fileId;
|
||||||
if (data instanceof stream.Stream) {
|
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 = {};
|
||||||
formData[type] = {
|
formData[type] = {
|
||||||
value: data,
|
value: data,
|
||||||
|
@@ -991,5 +991,10 @@ describe('TelegramBot', function telegramSuite() {
|
|||||||
assert.ok(err.response.body.indexOf('Bad Request') !== -1);
|
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
|
}); // End Telegram
|
||||||
|
Reference in New Issue
Block a user