Bugfix. Images being rendered when they shouldn't

This commit is contained in:
JC Brand 2021-06-17 12:45:22 +02:00
parent b071a0e22f
commit 2ac49fb9a5
2 changed files with 18 additions and 2 deletions

View File

@ -52,6 +52,22 @@ describe("A Chat Message", function () {
done();
}));
it("will not render images if show_images_inline is false",
mock.initConverse(['chatBoxesFetched'], {'show_images_inline': false}, async function (done, _converse) {
await mock.waitForRoster(_converse, 'current');
const base_url = 'https://conversejs.org';
const message = base_url+"/logo/conversejs-filled.svg";
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await mock.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
await mock.sendMessage(view, message);
const sel = '.chat-content .chat-msg:last .chat-msg__text';
await u.waitUntil(() => sizzle(sel).pop().innerHTML.replace(/<!-.*?->/g, '').trim() === message);
expect(true).toBe(true);
done();
}));
it("will render images from approved URLs only",
mock.initConverse(
['chatBoxesFetched'], {'show_images_inline': ['conversejs.org']},

View File

@ -90,14 +90,14 @@ u.isImageURL = url => {
u.isImageDomainAllowed = url => {
const show_images_inline = api.settings.get('show_images_inline');
if (!Array.isArray(show_images_inline)) {
return true;
return show_images_inline;
}
try {
const image_domain = getURI(url).domain();
return show_images_inline.includes(image_domain);
} catch (error) {
log.debug(error);
return true;
return false;
}
}