FIX: infinite loop when mentioning in IE11

FIX: infinite loop when mentioning in IE11

diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6
index 2abd120..020545e 100644
--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6
+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/text-post-process.js.es6
@@ -81,13 +81,16 @@ function allowedBoundary(content, index, utils) {
 }
 
 function textPostProcess(content, state, ruler) {
-  let result = null,
-    match,
-    pos = 0;
+  let result = null;
+  let match;
+  let pos = 0;
 
   const matcher = ruler.getMatcher();
 
-  while ((match = matcher.exec(content))) {
+  while (match = matcher.exec(content)) {
+    // something is wrong
+    if (match.index < pos) break;
+
     // check boundary
     if (match.index > 0) {
       if (!allowedBoundary(content, match.index - 1, state.md.utils)) {
@@ -104,15 +107,14 @@ function textPostProcess(content, state, ruler) {
       }
     }
 
+    result = result || [];
+
     if (match.index > pos) {
-      result = result || [];
       let token = new state.Token("text", "", 0);
       token.content = content.slice(pos, match.index);
       result.push(token);
     }
 
-    result = result || [];
-
     ruler.applyRule(result, match, state);
 
     pos = match.index + match[0].length;

GitHub sha: 1e4f0ac2