Move regex escaping to separate function.

This commit is contained in:
ccd0 2017-10-23 19:39:48 -07:00
parent c2b5a1f9f9
commit 407b5fe8a8

View File

@ -196,6 +196,32 @@ Filter =
if post.nodes.post.getBoundingClientRect().height
new Notice 'info', 'MD5 filtered.', 2
escape: (value) ->
value.replace ///
/
| \\
| \^
| \$
| \n
| \.
| \(
| \)
| \{
| \}
| \[
| \]
| \?
| \*
| \+
| \|
///g, (c) ->
if c is '\n'
'\\n'
else if c is '\\'
'\\\\'
else
"\\#{c}"
menu:
init: ->
return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] and Conf['Filter']
@ -248,31 +274,7 @@ Filter =
{type} = @dataset
# Convert value -> regexp, unless type is MD5
value = Filter[type] Filter.menu.post
re = if type in ['uniqueID', 'MD5'] then value else value.replace ///
/
| \\
| \^
| \$
| \n
| \.
| \(
| \)
| \{
| \}
| \[
| \]
| \?
| \*
| \+
| \|
///g, (c) ->
if c is '\n'
'\\n'
else if c is '\\'
'\\\\'
else
"\\#{c}"
re = if type in ['uniqueID', 'MD5'] then value else Filter.escape(value)
re = if type in ['uniqueID', 'MD5']
"/#{re}/"
else