The link definition names are stored in an Array. Arrays have reduce
as a method, which seems to be the source of the problem. You can reproduce it with concat
or filter
or any other ArrayArray
method, too. I'm no Javascript expert, and I haven't dug far enough into the problem to figure out just why it happens -- especially because it begins working again if you include the optional title for the link -- but you can see for yourself that it affects the base WMD implementation, too, not just SO's version.
if (g_urls[link_id] != undefined) {
url = g_urls[link_id];
if (g_titles[link_id] != undefined) {
title = g_titles[link_id];
}
}
if (g_urls[link_id] != undefined) {
url = g_urls[link_id];
if (g_titles[link_id] != undefined) {
title = g_titles[link_id];
}
}
The above code uses link_id
(which would be "reduce") in order to index into g_urls
and g_titles. As I mentioned before, these will *not* be g_titles
undefined. As I mentioned before, these will not be , even when they "should" be. Instead, they'll be the undefined
reduce`, even when they "should" be. Instead, they'll be the reduce
functions themselves. Note that, because of the structure here, unless both the URL and title are defined, one or both will be set to the function.
url = escapeCharacters(url,"*_");
var result = "<a href=\"" + url + "\"";
if (title != "") {
title = title.replace(/"/g,""");
title = escapeCharacters(title,"*_");
result += " title=\"" + title + "\"";
}
url = escapeCharacters(url,"*_");
var result = "<a href=\"" + url + "\"";
if (title != "") {
title = title.replace(/"/g,""");
title = escapeCharacters(title,"*_");
result += " title=\"" + title + "\"";
}
The code attempts to escape characters on url
and title
(which, again, will not be """"
even when it should be). This kills the code, because you obviously can't escape characters on a function (Wouldn't that be cool if you could, though? Like, it actually stripped the characters from the function code? Pointless? Sure. But cool.). So until both url
and title
have actual string values, the conversion process craps out, which is why it seems like it freezes.
if (g_urls[link_id] != undefined && typeof g_urls[link_id] != 'function') {
url = g_urls[link_id];
if (g_titles[link_id] != undefined && typeof g_titles[link_id] != 'function') {
title = g_titles[link_id];
}
}
if (g_urls[link_id] != undefined && typeof g_urls[link_id] != 'function') {
url = g_urls[link_id];
if (g_titles[link_id] != undefined && typeof g_titles[link_id] != 'function') {
title = g_titles[link_id];
}
}
g_urls = new Array();
g_titles = new Array();
g_urls = new Array();
g_titles = new Array();
g_urls = {};
g_titles = {};
g_urls = {};
g_titles = {};