fixed null handling for regex matching

This commit is contained in:
Akinwale Ariwodola 2017-09-24 14:02:42 +01:00
parent 7d92f29676
commit 929c1ea9ae

5
app.js
View file

@ -653,7 +653,7 @@ const doSendTip = (body, message, callback) => {
let amountLbc = 0; let amountLbc = 0;
let matchedString = ''; let matchedString = '';
const match = String(message.data.body).match(tipRegex); const match = String(message.data.body).match(tipRegex);
if (match.length > 0) { if (match && match.length > 0) {
matchedString = match[0]; matchedString = match[0];
if (matchedString.indexOf(' ') > -1) { if (matchedString.indexOf(' ') > -1) {
const parts = matchedString.split(' ', 2); const parts = matchedString.split(' ', 2);
@ -940,7 +940,8 @@ const processMessage = function(message, callback) {
} }
if (message.kind === commentKind) { if (message.kind === commentKind) {
if (body.match(gildRegex).length > 0) { const gildMatch = body.match(gildRegex);
if (gildMatch && gildMatch.length > 0) {
doGild(message, callback); doGild(message, callback);
} else { } else {
doSendTip(body, message, callback); doSendTip(body, message, callback);