JS regex's need to escape special chars

LMS-11260
This commit is contained in:
Don Mitchell
2014-08-25 17:00:48 -04:00
parent 4465b26a43
commit 49ed732824

View File

@@ -35,8 +35,9 @@ window.rewriteStaticLinks = function(content, from, to) {
}
// change all relative urls only which may be embedded inside other tags in content.
// handle http and https
// note: add other protocols here
var regex = new RegExp("(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}([-a-zA-Z0-9@:%_\+.~#?&//=]*))?"+from, 'g');
// escape all regex interpretable chars
fromRe = from.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var regex = new RegExp("(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}([-a-zA-Z0-9@:%_\+.~#?&//=]*))?"+fromRe, 'g');
return content.replace(regex, replacer);
};