Skip to content

Commit ebf94df

Browse files
heldersepushockey
authored andcommitted
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
1 parent 6ba93ad commit ebf94df

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/core/components/providers/markdown.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const sanitizeOptions = {
4646
"td": [ "colspan" ],
4747
"*": [ "class" ]
4848
},
49+
allowedSchemesByTag: { img: [ "http", "https", "data" ] },
4950
textFilter: function(text) {
5051
return text.replace(/"/g, "\"")
5152
}

test/components/markdown.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ describe("Markdown component", function() {
2424
const el = render(<Markdown source={str} />)
2525
expect(el.html()).toEqual(`<div class="markdown"><p><img src="http://image.source" title="Image title"></p>\n</div>`)
2626
})
27+
28+
it("allows image elements with https scheme", function() {
29+
const str = `![Image alt text](https://image.source "Image title")`
30+
const el = render(<Markdown source={str} />)
31+
expect(el.html()).toEqual(`<div class="markdown"><p><img src="https://image.source" title="Image title"></p>\n</div>`)
32+
})
33+
34+
it("allows image elements with data scheme", function() {
35+
const str = `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==">`
36+
const el = render(<Markdown source={str} />)
37+
expect(el.html()).toEqual(`<div class="markdown"><p>` + str + `</p>\n</div>`)
38+
})
2739

2840
it("allows heading elements", function() {
2941
const str = `
@@ -51,6 +63,18 @@ describe("Markdown component", function() {
5163
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="http://image.source" title="Image title"></p></div></div>`)
5264
})
5365

66+
it("allows image elements with https scheme", function() {
67+
const str = `![Image alt text](https://image.source "Image title")`
68+
const el = render(<OAS3Markdown source={str} />)
69+
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="https://image.source" title="Image title"></p></div></div>`)
70+
})
71+
72+
it("allows image elements with data scheme", function() {
73+
const str = `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==">`
74+
const el = render(<OAS3Markdown source={str} />)
75+
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div>` + str + `</div></div>`)
76+
})
77+
5478
it("allows heading elements", function() {
5579
const str = `
5680
# h1

0 commit comments

Comments
 (0)