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

test(markdown-fixtures): add a test for DOMPurify sanitization #703

Merged
merged 1 commit into from
Apr 18, 2023
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
6 changes: 6 additions & 0 deletions src/fixtures/markdown-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ export const maliciousJsonObject = {
},
pageContent: maliciousPageContent,
}

export const rawInstagramEmbedScript =
'<script src="//www.instagram.com/embed.js" async></script>'

export const sanitizedInstagramEmbedScript =
'<script async="" src="//www.instagram.com/embed.js"></script>'
12 changes: 12 additions & 0 deletions src/utils/__tests__/markdown-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
maliciousMarkdownContent,
normalJsonObject,
maliciousJsonObject,
rawInstagramEmbedScript,
sanitizedInstagramEmbedScript,
} from "@fixtures/markdown-fixtures"
import { sanitizer } from "@root/services/utilServices/Sanitizer"

describe("Sanitized markdown utils test", () => {
it("should parse normal markdown content into an object successfully", () => {
Expand Down Expand Up @@ -36,4 +39,13 @@ describe("Sanitized markdown utils test", () => {
normalMarkdownContent
)
})

it("should sanitize boolean tags with an empty string", () => {
// NOTE: Setting a boolean attr to an empty string is equivalent
// to it being true.
// See the HTML spec: https://html.spec.whatwg.org/#boolean-attributes
expect(sanitizer.sanitize(rawInstagramEmbedScript)).toBe(
sanitizedInstagramEmbedScript
)
})
})