From 9d12bdfa41e5f22062543a33cd53798e61dc489f Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Fri, 3 Feb 2017 10:16:19 +0300 Subject: [PATCH] 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 --- CHANGELOG.md | 2 ++ src/telegramWebHook.js | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72f9522..908382f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Added: 1. Add health-check endpoint (by @mironov) * `options.webHook.healthEndpoint` +1. Use *String#indexOf()*, instead of *RegExp#test()*, to + find token in webhook request (by @AVVS) * * * diff --git a/src/telegramWebHook.js b/src/telegramWebHook.js index d4db943..b8f29f9 100644 --- a/src/telegramWebHook.js +++ b/src/telegramWebHook.js @@ -30,7 +30,6 @@ class TelegramBotWebHook { this.options.https = options.https || {}; this.options.healthEndpoint = options.healthEndpoint || '/healthz'; this.callback = callback; - this._regex = new RegExp(this.token); this._healthRegex = new RegExp(this.options.healthEndpoint); this._webServer = null; this._open = false; @@ -138,7 +137,7 @@ class TelegramBotWebHook { debug('WebHook request URL: %s', req.url); debug('WebHook request headers: %j', req.headers); - if (this._regex.test(req.url)) { + if (req.url.indexOf(this.token) !== -1) { if (req.method !== 'POST') { debug('WebHook request isn\'t a POST'); res.statusCode = 418; // I'm a teabot!