From: Mischa POSLAWSKY Date: Wed, 16 Dec 2020 13:05:11 +0000 (+0100) Subject: edit/page: enforce relative links to local domain X-Git-Tag: v5.0~7 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/d877282196bdf97f4edc63fd63b4f1a1445bc678 edit/page: enforce relative links to local domain Replace and urls on save to fix common user mistake breaking site deployment on a different [dev] domain. --- diff --git a/edit/page.js b/edit/page.js index f927c1f..45d9e64 100644 --- a/edit/page.js +++ b/edit/page.js @@ -28,6 +28,10 @@ CKEDITOR.plugins.add('inlinesave', { }); // treat standalone placeholders as block elements body = body.replace(/

(\[\[.*\]\])<\/p>/g, '$1'); + // strip redundant domain in relative urls + var hostlink = 'https?://' + window.location.hostname.replace(/\W/g, '\\$&'); + hostlink = new RegExp('(]*href="|]*src=")' + hostlink + '(?=/)', 'gi'); + body = body.replace(hostlink, '$1'); var data = 'body='+encodeURIComponent(body); var ajaxpost = new XMLHttpRequest();