diff --git a/common/static/js/spec/utility_spec.js b/common/static/js/spec/utility_spec.js index 6e19798026..c44d36e893 100644 --- a/common/static/js/spec/utility_spec.js +++ b/common/static/js/spec/utility_spec.js @@ -10,4 +10,9 @@ describe('utility.rewriteStaticLinks', function () { it('returns "content" if "from" is not found', function () { expect(rewriteStaticLinks('', '/statix/', 'howdy')).toBe('') }); + it('does not replace of "from" to "to" if "from" is part of absolute url', function () { + expect( + rewriteStaticLinks('', '/static/', 'howdy') + ).toBe('') + }); }); diff --git a/common/static/js/src/utility.js b/common/static/js/src/utility.js index d3ed461b38..7b5dd5a6bb 100644 --- a/common/static/js/src/utility.js +++ b/common/static/js/src/utility.js @@ -24,7 +24,18 @@ window.rewriteStaticLinks = function(content, from, to) { if (from === null || to === null) { return content; } - - var regex = new RegExp(from, 'g'); - return content.replace(regex, to); -}; + // replace only relative urls + function replacer(match){ + if (match === from){ + return to; + } + else { + return match; + } + } + // 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'); + return content.replace(regex, replacer); +}; \ No newline at end of file diff --git a/common/static/js/vendor/tiny_mce/tiny_mce_popup.js b/common/static/js/vendor/tiny_mce/tiny_mce_popup.js index bb8e58c88a..b726d1ad1a 100644 --- a/common/static/js/vendor/tiny_mce/tiny_mce_popup.js +++ b/common/static/js/vendor/tiny_mce/tiny_mce_popup.js @@ -2,4 +2,6 @@ // Uncomment and change this document.domain value if you are loading the script cross subdomains // document.domain = 'moxiecode.com'; -var tinymce=null,tinyMCEPopup,tinyMCE;tinyMCEPopup={init:function(){var b=this,a,c;a=b.getWin();tinymce=a.tinymce;tinyMCE=a.tinyMCE;b.editor=tinymce.EditorManager.activeEditor;b.params=b.editor.windowManager.params;b.features=b.editor.windowManager.features;b.dom=b.editor.windowManager.createInstance("tinymce.dom.DOMUtils",document,{ownEvents:true,proxy:tinyMCEPopup._eventProxy});b.dom.bind(window,"ready",b._onDOMLoaded,b);if(b.features.popup_css!==false){b.dom.loadCSS(b.features.popup_css||b.editor.settings.popup_css)}b.listeners=[];b.onInit={add:function(e,d){b.listeners.push({func:e,scope:d})}};b.isWindow=!b.getWindowArg("mce_inline");b.id=b.getWindowArg("mce_window_id");b.editor.windowManager.onOpen.dispatch(b.editor.windowManager,window)},getWin:function(){return(!window.frameElement&&window.dialogArguments)||opener||parent||top},getWindowArg:function(c,b){var a=this.params[c];return tinymce.is(a)?a:b},getParam:function(b,a){return this.editor.getParam(b,a)},getLang:function(b,a){return this.editor.getLang(b,a)},execCommand:function(d,c,e,b){b=b||{};b.skip_focus=1;this.restoreSelection();return this.editor.execCommand(d,c,e,b)},resizeToInnerSize:function(){var a=this;setTimeout(function(){var b=a.dom.getViewPort(window);a.editor.windowManager.resizeBy(a.getWindowArg("mce_width")-b.w,a.getWindowArg("mce_height")-b.h,a.id||window)},10)},executeOnLoad:function(s){this.onInit.add(function(){eval(s)})},storeSelection:function(){this.editor.windowManager.bookmark=tinyMCEPopup.editor.selection.getBookmark(1)},restoreSelection:function(){var a=tinyMCEPopup;if(!a.isWindow&&tinymce.isIE){a.editor.selection.moveToBookmark(a.editor.windowManager.bookmark)}},requireLangPack:function(){var b=this,a=b.getWindowArg("plugin_url")||b.getWindowArg("theme_url");if(a&&b.editor.settings.language&&b.features.translate_i18n!==false&&b.editor.settings.language_load!==false){a+="/langs/"+b.editor.settings.language+"_dlg.js";if(!tinymce.ScriptLoader.isDone(a)){document.write('