Merge pull request #2626 from overleaf/bg-fix-editor-regexps

fix stateful regexp usage in editor inputs

GitOrigin-RevId: 4950066251cb6235e218ff4f600fab2652d15e76
This commit is contained in:
Eric Mc Sween
2020-02-28 04:18:33 +00:00
committed by Copybot
parent c120309dd0
commit 5f712645ed
@@ -201,29 +201,25 @@ define([
// you can modify the input or reject the event with e.preventDefault() // you can modify the input or reject the event with e.preventDefault()
editor.commands.on('exec', function(e) { editor.commands.on('exec', function(e) {
// replace bad characters in paste content // replace bad characters in paste content
if ( if (e.command && e.command.name === 'paste') {
e.command && BAD_CHARS_REGEXP.lastIndex = 0 // reset stateful regexp for this usage
e.command.name === 'paste' && if (e.args && BAD_CHARS_REGEXP.test(e.args.text)) {
e.args &&
BAD_CHARS_REGEXP.test(e.args.text)
) {
e.args.text = e.args.text.replace( e.args.text = e.args.text.replace(
BAD_CHARS_REGEXP, BAD_CHARS_REGEXP,
BAD_CHARS_REPLACEMENT_CHAR BAD_CHARS_REPLACEMENT_CHAR
) )
} }
}
// replace bad characters in keyboard input // replace bad characters in keyboard input
if ( if (e.command && e.command.name === 'insertstring') {
e.command && BAD_CHARS_REGEXP.lastIndex = 0 // reset stateful regexp for this usage
e.command.name === 'insertstring' && if (e.args && BAD_CHARS_REGEXP.test(e.args)) {
e.args &&
BAD_CHARS_REGEXP.test(e.args)
) {
e.args = e.args.replace( e.args = e.args.replace(
BAD_CHARS_REGEXP, BAD_CHARS_REGEXP,
BAD_CHARS_REPLACEMENT_CHAR BAD_CHARS_REPLACEMENT_CHAR
) )
} }
}
}) })
/* eslint-enable no-unused-vars */ /* eslint-enable no-unused-vars */