2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

src/webhook: Use String#indexOf() instead of RegExp#test() to find token

References:

  * Original PR: https://github.com/yagop/node-telegram-bot-api/pull/147
  * Original Author: @AVVS
This commit is contained in:
GochoMugo 2017-02-03 10:16:19 +03:00
parent 2013f6cffa
commit 9d12bdfa41
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
2 changed files with 3 additions and 2 deletions

View File

@ -9,6 +9,8 @@ Added:
1. Add health-check endpoint (by @mironov) 1. Add health-check endpoint (by @mironov)
* `options.webHook.healthEndpoint` * `options.webHook.healthEndpoint`
1. Use *String#indexOf()*, instead of *RegExp#test()*, to
find token in webhook request (by @AVVS)
* * * * * *

View File

@ -30,7 +30,6 @@ class TelegramBotWebHook {
this.options.https = options.https || {}; this.options.https = options.https || {};
this.options.healthEndpoint = options.healthEndpoint || '/healthz'; this.options.healthEndpoint = options.healthEndpoint || '/healthz';
this.callback = callback; this.callback = callback;
this._regex = new RegExp(this.token);
this._healthRegex = new RegExp(this.options.healthEndpoint); this._healthRegex = new RegExp(this.options.healthEndpoint);
this._webServer = null; this._webServer = null;
this._open = false; this._open = false;
@ -138,7 +137,7 @@ class TelegramBotWebHook {
debug('WebHook request URL: %s', req.url); debug('WebHook request URL: %s', req.url);
debug('WebHook request headers: %j', req.headers); debug('WebHook request headers: %j', req.headers);
if (this._regex.test(req.url)) { if (req.url.indexOf(this.token) !== -1) {
if (req.method !== 'POST') { if (req.method !== 'POST') {
debug('WebHook request isn\'t a POST'); debug('WebHook request isn\'t a POST');
res.statusCode = 418; // I'm a teabot! res.statusCode = 418; // I'm a teabot!