aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-04-19 18:11:53 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-04-19 18:11:53 -1000
commit7750ee481b305ff8789ca9813da2c62182b25b06 (patch)
tree5e39039ca4bb8569a87bc48f708683113deff8c9 /lib
parent644220073961892fb5fbd673e8c6aee488ba0ad6 (diff)
downloadpatchfoo-7750ee481b305ff8789ca9813da2c62182b25b06.tar.gz
patchfoo-7750ee481b305ff8789ca9813da2c62182b25b06.zip
Handle invalid regex
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/app.js b/lib/app.js
index cd4691f..3803281 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -252,8 +252,16 @@ function forSome(each) {
function filterByText(str) {
if (!str) return function () { return true }
- var search = new RegExp(str, 'i')
- var matches = forSome(search.test.bind(search))
+ var matcher
+ try {
+ var search = new RegExp(str, 'i')
+ matcher = search.test.bind(search)
+ } catch(e) {
+ matcher = function (value) {
+ return String(value).indexOf(str) !== -1
+ }
+ }
+ var matches = forSome(matcher)
return function (msg) {
var c = msg.value.content
return c && matches(c)