Commit 7750ee481b305ff8789ca9813da2c62182b25b06
Handle invalid regex
cel committed on 4/20/2019, 4:11:53 AMParent: 644220073961892fb5fbd673e8c6aee488ba0ad6
Files changed
lib/app.js | changed |
lib/app.js | ||
---|---|---|
@@ -251,10 +251,18 @@ | ||
251 | 251 … | } |
252 | 252 … | |
253 | 253 … | function filterByText(str) { |
254 | 254 … | if (!str) return function () { return true } |
255 | - var search = new RegExp(str, 'i') | |
256 | - var matches = forSome(search.test.bind(search)) | |
255 … | + var matcher | |
256 … | + try { | |
257 … | + var search = new RegExp(str, 'i') | |
258 … | + matcher = search.test.bind(search) | |
259 … | + } catch(e) { | |
260 … | + matcher = function (value) { | |
261 … | + return String(value).indexOf(str) !== -1 | |
262 … | + } | |
263 … | + } | |
264 … | + var matches = forSome(matcher) | |
257 | 265 … | return function (msg) { |
258 | 266 … | var c = msg.value.content |
259 | 267 … | return c && matches(c) |
260 | 268 … | } |
Built with git-ssb-web