From 92dbb759bc70d317883590fc93f4f2e6baacf811 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 23 Jan 2011 18:20:11 -0500 Subject: [PATCH] Fix arbitrary limit on the number of substrings to highlight in template.highlightSubstrings. --HG-- extra : transplant_source : %C4%94%92%C9x%D0%94%25%9A%9C%0B%1B%F5%0C%26%94GT9%09 --- common/modules/template.jsm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 1cd8764a..36847f6d 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -182,10 +182,12 @@ var Template = Module("Template", { str = String(str).replace(" ", "\u00a0"); let s = <>; let start = 0; - let n = 0; + let n = 0, _i; for (let [i, length, args] in iter) { - if (n++ > 50) // Prevent infinite loops. + if (i == _i || i < _i) break; + _i = i; + XML.ignoreWhitespace = false; s += <>{str.substring(start, i)}; s += highlight.apply(this, Array.concat(args || str.substr(i, length))); @@ -227,14 +229,13 @@ var Template = Module("Template", { linkifyHelp: function linkifyHelp(str, help) { let re = util.regexp( ) - (?=[[!,;./\s]|$) + (?P
 [/\s]|^)
+            (?P '[\w-]+' | :(?:[\w-]+|!) | (?:._)?<[\w-]+> )
+            (?=      [[!,;./\s]|$)
         ]]>, "g");
         return this.highlightSubstrings(str, (function () {
-            let res;
-            while ((res = re.exec(str)) && res[2].length)
-                yield [res.index + res[1].length, res[2].length];
+            for (let res in re.iterate(str))
+                yield [res.index + res.pre.length, res.tag.length];
         })(), template[help ? "HelpLink" : "helpLink"]);
     },