From d877282196bdf97f4edc63fd63b4f1a1445bc678 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 16 Dec 2020 14:05:11 +0100 Subject: [PATCH] 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. --- edit/page.js | 4 ++++ 1 file changed, 4 insertions(+) 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(); -- 2.30.0