Prevent link exploit
This commit is contained in:
parent
95df0ccec7
commit
0e7d3b93cd
File diff suppressed because one or more lines are too long
|
@ -1,9 +1,10 @@
|
|||
function escape(text) {
|
||||
var e = {
|
||||
"<": "<",
|
||||
">": ">"
|
||||
">": ">",
|
||||
"'": """
|
||||
};
|
||||
return text.replace(/[<>]/g, function (c) {
|
||||
return text.replace(/[<>']/g, function (c) {
|
||||
return e[c];
|
||||
});
|
||||
}
|
||||
|
@ -18,9 +19,12 @@ Handlebars.registerHelper(
|
|||
text = escape(text);
|
||||
for (var i in urls) {
|
||||
var url = escape(urls[i]);
|
||||
var replace = url;
|
||||
if (url.indexOf("javascript:") !== 0) {
|
||||
replace = "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
|
||||
}
|
||||
text = text.replace(
|
||||
"$(" + i + ")",
|
||||
"<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>"
|
||||
"$(" + i + ")", replace
|
||||
);
|
||||
}
|
||||
return text;
|
||||
|
|
Loading…
Reference in New Issue