mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-31 14:25:57 +00:00
src/telegram: reset state of global regexp (#326)
References: * BR: https://github.com/yagop/node-telegram-bot-api/issues/325 * BR-by: @Sirius-A * PR: https://github.com/yagop/node-telegram-bot-api/pull/326 * PR-by: @Sirius-A
This commit is contained in:
@@ -473,6 +473,8 @@ class TelegramBot extends EventEmitter {
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
// reset index so we start at the beginning of the regex each time
|
||||
reg.regexp.lastIndex = 0;
|
||||
debug('Matches %s', reg.regexp);
|
||||
reg.callback(message, result);
|
||||
// returning truthy value exits .some
|
||||
|
@@ -975,6 +975,16 @@ describe('TelegramBot', function telegramSuite() {
|
||||
message: { text: '/onText ECHO ALOHA' },
|
||||
});
|
||||
});
|
||||
it('should reset the global regex state with each message', function test(done) {
|
||||
const regexp = /\/onText (.+)/g;
|
||||
botWebHook.onText(regexp, () => {
|
||||
assert.equal(regexp.lastIndex, 0);
|
||||
return done();
|
||||
});
|
||||
utils.sendWebHookMessage(webHookPort2, TOKEN, {
|
||||
message: { text: '/onText ECHO ALOHA' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#onReplyToMessage', function onReplyToMessageSuite() {});
|
||||
|
Reference in New Issue
Block a user