Skip to content

Commit

Permalink
πŸ› Fixed mobiledoc returning relative asset urls
Browse files Browse the repository at this point in the history
refs TryGhost#10620, refs TryGhost#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"
  • Loading branch information
kirrg001 committed Mar 22, 2019
1 parent 1e6f4ba commit 5db1dc0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5db1dc0

Please sign in to comment.