Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refuse to render non-string Markdown field values #5295

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/components/providers/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ DomPurify.addHook("beforeSanitizeElements", function (current, ) {
const isPlainText = (str) => /^[A-Z\s0-9!?\.]+$/gi.test(str)

function Markdown({ source, className = "" }) {
if (typeof source !== "string") {
return null
}

if(isPlainText(source)) {
// If the source text is not Markdown,
// let's save some time and just render it.
Expand Down
4 changes: 4 additions & 0 deletions src/core/plugins/oas3/wrap-components/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ parser.block.ruler.enable(["table"])
parser.set({ linkTarget: "_blank" })

export const Markdown = ({ source, className = "" }) => {
if(typeof source !== "string") {
return null
}

if ( source ) {
const html = parser.render(source)
const sanitized = sanitizer(html)
Expand Down