Merge pull request #1911 from overleaf/bg-block-non-bmp-characters

block null and non-BMP characters in Ace

GitOrigin-RevId: cdeaffc88e128a62463229d5cb55143028f23112
This commit is contained in:
Brian Gough 2019-06-26 11:50:52 +01:00 committed by sharelatex
parent bd3f59c22a
commit 30d8247d54

View file

@ -198,6 +198,38 @@ define([
files
)
// prevent user entering null and non-BMP unicode characters in Ace
const BAD_CHARS_REGEXP = /[\0\uD800-\uDFFF]/g
const BAD_CHARS_REPLACEMENT_CHAR = '\uFFFD'
// the 'exec' event fires for ace functions before they are executed.
// you can modify the input or reject the event with e.preventDefault()
editor.commands.on('exec', function(e) {
// replace bad characters in paste content
if (
e.command &&
e.command.name === 'paste' &&
e.args &&
BAD_CHARS_REGEXP.test(e.args.text)
) {
e.args.text = e.args.text.replace(
BAD_CHARS_REGEXP,
BAD_CHARS_REPLACEMENT_CHAR
)
}
// replace bad characters in keyboard input
if (
e.command &&
e.command.name === 'insertstring' &&
e.args &&
BAD_CHARS_REGEXP.test(e.args)
) {
e.args = e.args.replace(
BAD_CHARS_REGEXP,
BAD_CHARS_REPLACEMENT_CHAR
)
}
})
/* eslint-enable no-unused-vars */
scope.$watch('onSave', function(callback) {