|
|
@@ -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) {
|