Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 4073be4

Browse files
author
Zirak
committed
Fixed substitution (s///).
There were two problems with minification: First, the substitution's matcher function (passed into `bot.eval`) referenced an argument `eval` brought it, but which was not actually in the function's lexical scope. Fix is to explicitly use `arguments`. Second, to return the result, the matcher simply left a variable dangling around at the end of the function (as `eval` picks up the last expression's value as the result), which was minified away. Fix is to wrap it around in an IIFE so it won't appear to be a no-op.
1 parent dc80fa1 commit 4073be4

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

master.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5803,7 +5803,8 @@ function getMatchingMessage ( re, onlyBefore, cb ) {
58035803
//to bot.eval
58045804
// we do the skip and jump through bot.eval to avoid a ReDoS (#217).
58055805
var matcher = function () {
5806-
var matchIndex = null;
5806+
var arg = arguments[1],
5807+
matchIndex = null;
58075808

58085809
arg.messages.some(function ( msg, idx ) {
58095810
if ( msg.id < arg.maxId && arg.pattern.test(msg.text) ) {
@@ -5815,10 +5816,16 @@ function getMatchingMessage ( re, onlyBefore, cb ) {
58155816
});
58165817

58175818
// remember we're inside bot.eval, final expression is the result.
5818-
matchIndex;
5819+
// so it'll work well with minification, we have to create an expression
5820+
//which won't be removed
5821+
(function () {
5822+
return matchIndex;
5823+
})();
58195824
};
58205825

58215826
bot.eval( matcher.stringContents(), arg, function ( err, resp ) {
5827+
bot.log( err, resp, 'substitution matcher response' );
5828+
58225829
// meh
58235830
if ( err ) {
58245831
cb( err );

0 commit comments

Comments
 (0)