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
This commit is contained in:
Helder Sepulveda
2018-03-08 20:17:30 -05:00
committed by kyle
parent 6ba93ad43f
commit ebf94dfccf
2 changed files with 25 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ const sanitizeOptions = {
"td": [ "colspan" ], "td": [ "colspan" ],
"*": [ "class" ] "*": [ "class" ]
}, },
allowedSchemesByTag: { img: [ "http", "https", "data" ] },
textFilter: function(text) { textFilter: function(text) {
return text.replace(/"/g, "\"") return text.replace(/"/g, "\"")
} }

View File

@@ -25,6 +25,18 @@ describe("Markdown component", function() {
expect(el.html()).toEqual(`<div class="markdown"><p><img src="http://image.source" title="Image title"></p>\n</div>`) expect(el.html()).toEqual(`<div class="markdown"><p><img src="http://image.source" title="Image title"></p>\n</div>`)
}) })
it("allows image elements with https scheme", function() {
const str = `![Image alt text](https://image.source "Image title")`
const el = render(<Markdown source={str} />)
expect(el.html()).toEqual(`<div class="markdown"><p><img src="https://image.source" title="Image title"></p>\n</div>`)
})
it("allows image elements with data scheme", function() {
const str = `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==">`
const el = render(<Markdown source={str} />)
expect(el.html()).toEqual(`<div class="markdown"><p>` + str + `</p>\n</div>`)
})
it("allows heading elements", function() { it("allows heading elements", function() {
const str = ` const str = `
# h1 # h1
@@ -51,6 +63,18 @@ describe("Markdown component", function() {
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="http://image.source" title="Image title"></p></div></div>`) expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="http://image.source" title="Image title"></p></div></div>`)
}) })
it("allows image elements with https scheme", function() {
const str = `![Image alt text](https://image.source "Image title")`
const el = render(<OAS3Markdown source={str} />)
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="https://image.source" title="Image title"></p></div></div>`)
})
it("allows image elements with data scheme", function() {
const str = `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==">`
const el = render(<OAS3Markdown source={str} />)
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div>` + str + `</div></div>`)
})
it("allows heading elements", function() { it("allows heading elements", function() {
const str = ` const str = `
# h1 # h1