mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
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:
parent
bd3f59c22a
commit
30d8247d54
1 changed files with 32 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue