提交 8ba3cdaa 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

escape ' for filter function #116

上级 28ef8c65
......@@ -201,6 +201,7 @@ export class Contact implements Sayable {
if (nameFilter instanceof RegExp) {
filterFunction = `(function (c) { return ${nameFilter.toString()}.test(c) })`
} else if (typeof nameFilter === 'string') {
nameFilter = nameFilter.replace(/'/g, '\\\'')
filterFunction = `(function (c) { return c === '${nameFilter}' })`
} else {
throw new Error('unsupport name type')
......
......@@ -426,6 +426,7 @@ export class Room extends EventEmitter implements Sayable {
if (topicFilter instanceof RegExp) {
filterFunction = `(function (c) { return ${topicFilter.toString()}.test(c) })`
} else if (typeof topicFilter === 'string') {
topicFilter = topicFilter.replace(/'/g, '\\\'')
filterFunction = `(function (c) { return c === '${topicFilter}' })`
} else {
throw new Error('unsupport topic type')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册