From ebf94dfccff45bed13974b8afaea9873101cf7dd Mon Sep 17 00:00:00 2001 From: Helder Sepulveda Date: Thu, 8 Mar 2018 20:17:30 -0500 Subject: [PATCH] Allow images with data scheme (#4305) * Add UnitTest for images allows image elements with https scheme * Test images with data scheme * Add allowedSchemesByTag * Fix error Strings must use doublequote quotes --- src/core/components/providers/markdown.jsx | 1 + test/components/markdown.js | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/core/components/providers/markdown.jsx b/src/core/components/providers/markdown.jsx index a4cbf3f9..9707ece6 100644 --- a/src/core/components/providers/markdown.jsx +++ b/src/core/components/providers/markdown.jsx @@ -46,6 +46,7 @@ const sanitizeOptions = { "td": [ "colspan" ], "*": [ "class" ] }, + allowedSchemesByTag: { img: [ "http", "https", "data" ] }, textFilter: function(text) { return text.replace(/"/g, "\"") } diff --git a/test/components/markdown.js b/test/components/markdown.js index c3a716a3..cf208510 100644 --- a/test/components/markdown.js +++ b/test/components/markdown.js @@ -24,6 +24,18 @@ describe("Markdown component", function() { const el = render() expect(el.html()).toEqual(`

\n
`) }) + + it("allows image elements with https scheme", function() { + const str = `![Image alt text](https://image.source "Image title")` + const el = render() + expect(el.html()).toEqual(`

\n
`) + }) + + it("allows image elements with data scheme", function() { + const str = `` + const el = render() + expect(el.html()).toEqual(`

` + str + `

\n
`) + }) it("allows heading elements", function() { const str = ` @@ -51,6 +63,18 @@ describe("Markdown component", function() { expect(el.html()).toEqual(`

`) }) + it("allows image elements with https scheme", function() { + const str = `![Image alt text](https://image.source "Image title")` + const el = render() + expect(el.html()).toEqual(`

`) + }) + + it("allows image elements with data scheme", function() { + const str = `` + const el = render() + expect(el.html()).toEqual(`
` + str + `
`) + }) + it("allows heading elements", function() { const str = ` # h1