MDL-24507 tinymce moodleemoticon plugin replaces all occurrences of emoticon text...
[moodle.git] / lib / editor / tinymce / tiny_mce / 3.3.9.2 / plugins / moodleemoticon / editor_plugin_src.js
index c1f7954..51e3022 100644 (file)
                 var data = ed.getContent();
                 this._emoticons = tinymce.util.JSON.parse(ed.getParam('moodleemoticon_emoticons'));
                 for (var emotxt in this._emoticons) {
-                    data = data.replace(emotxt, this._emoticons[emotxt]);
+                    // escape the metacharacters so we can use it as regexp
+                    search = emotxt.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
+                    // convert to regexp
+                    search = new RegExp(search, 'g');
+                    // and replace all occurrences of it with the image
+                    data = data.replace(search, this._emoticons[emotxt]);
                 }
                 ed.setContent(data);
             });