From 5db1dc0d729ada73975cc456638e747d37e470d2 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Fri, 22 Mar 2019 12:18:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20mobiledoc=20returning=20?= =?UTF-8?q?relative=20asset=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #10620, refs #10477 - editor uploads an image - receives absolute path - inserts into mobiledoc - updates post - server stores relative asset paths - we need to serve absolute asset paths, otherwise editor could mark content as "dirty" --- .../api/v2/utils/serializers/output/utils/url.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/server/api/v2/utils/serializers/output/utils/url.js b/core/server/api/v2/utils/serializers/output/utils/url.js index ba12e2bd2a37..4aa40674ddb5 100644 --- a/core/server/api/v2/utils/serializers/output/utils/url.js +++ b/core/server/api/v2/utils/serializers/output/utils/url.js @@ -64,6 +64,20 @@ const forPost = (id, attrs, frame) => { ).html(); } + // CASE: we always need to return absolute urls for content urls + if (attrs.mobiledoc && !localUtils.isContentAPI(frame)) { + const imagePathRe = new RegExp(`/${urlService.utils.STATIC_IMAGE_URL_PREFIX}`, 'g'); + + const matches = _.uniq(attrs.mobiledoc.match(imagePathRe)); + + if (matches) { + matches.forEach((match) => { + const relative = urlService.utils.relativeToAbsolute(match); + attrs.mobiledoc = attrs.mobiledoc.replace(new RegExp(match, 'g'), relative); + }); + } + } + if (frame.options.columns && !frame.options.columns.includes('url')) { delete attrs.url; }