Skip to content

Commit f2a8ed0

Browse files
heldersepushockey
authored andcommitted
improve(sanitizer): add more allowed attributes (#4194)
* Add a couple of items to the sanitizeOptions * Strings must use doublequote quotes
1 parent 7fd229f commit f2a8ed0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/core/components/providers/markdown.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ Markdown.propTypes = {
2929
export default Markdown
3030

3131
const sanitizeOptions = {
32-
allowedTags: sanitize.defaults.allowedTags.concat([ "h1", "h2", "img" ]),
32+
allowedTags: sanitize.defaults.allowedTags.concat([ "h1", "h2", "img", "span" ]),
3333
allowedAttributes: {
3434
...sanitize.defaults.allowedAttributes,
35-
"img": sanitize.defaults.allowedAttributes.img.concat(["title"])
35+
"img": sanitize.defaults.allowedAttributes.img.concat(["title"]),
36+
"td": [ "colspan" ],
37+
"*": [ "class" ]
3638
},
3739
textFilter: function(text) {
3840
return text.replace(/"/g, "\"")

test/components/markdown.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import { Markdown as OAS3Markdown } from "corePlugins/oas3/wrap-components/markd
77

88
describe("Markdown component", function() {
99
describe("Swagger 2.0", function() {
10+
it("allows span elements with class attrib", function() {
11+
const str = `<span class="method">ONE</span>`
12+
const el = render(<Markdown source={str} />)
13+
expect(el.html()).toEqual(`<div class="markdown"><p><span class="method">ONE</span></p>\n</div>`)
14+
})
15+
16+
it("allows td elements with colspan attrib", function() {
17+
const str = `<table><tr><td>ABC</td></tr></table>`
18+
const el = render(<Markdown source={str} />)
19+
expect(el.html()).toEqual(`<div class="markdown"><table><tr><td>ABC</td></tr></table></div>`)
20+
})
21+
1022
it("allows image elements", function() {
1123
const str = `![Image alt text](http://image.source "Image title")`
1224
const el = render(<Markdown source={str} />)

0 commit comments

Comments
 (0)