[CORL-264] Fixes bug with purify (#2187)

* fix: fixed bug with purify

* refactor: changed variable assignment default

* refactor: fixed default variable assignment

* fix: repaired tests for <strong> -> <b>
This commit is contained in:
Wyatt Johnson
2019-02-11 18:22:43 +00:00
committed by GitHub
parent 710de07fa6
commit 3d7cb42434
12 changed files with 55 additions and 97 deletions
@@ -7,10 +7,10 @@ import { PropTypesOf } from "talk-framework/types";
it("renders correctly", () => {
const props: PropTypesOf<typeof CommentContent> = {
suspectWords: ["idiot", "damn"],
bannedWords: ["fuck", "fucking"],
suspectWords: ["worse"],
bannedWords: ["bad"],
className: "custom",
children: "Hello <strong>idiot</strong>, you fucking bastard",
children: "Hello <b>Bob</b>, you bad guy",
};
const renderer = createRenderer();
renderer.render(<CommentContent {...props} />);
@@ -22,7 +22,7 @@ it("renders empty words correctly", () => {
suspectWords: [],
bannedWords: [],
className: "custom",
children: "Hello <strong>idiot</strong>, you fucking bastard",
children: "Hello <b>Bob</b>, you bad guy",
};
const renderer = createRenderer();
renderer.render(<CommentContent {...props} />);
@@ -6,7 +6,7 @@ exports[`renders correctly 1`] = `
container="div"
dangerouslySetInnerHTML={
Object {
"__html": "Hello <strong><span><mark>idiot</mark></span></strong><span>, you <mark>fucking</mark> bastard</span>",
"__html": "Hello <b>Bob</b><span>, you <mark>bad</mark> guy</span>",
}
}
/>
@@ -18,7 +18,7 @@ exports[`renders empty words correctly 1`] = `
container="div"
dangerouslySetInnerHTML={
Object {
"__html": "Hello <strong>idiot</strong>, you fucking bastard",
"__html": "Hello <b>Bob</b>, you bad guy",
}
}
/>
@@ -62,7 +62,7 @@ exports[`post a comment: optimistic response 1`] = `
className="HTMLContent-root"
dangerouslySetInnerHTML={
Object {
"__html": "<strong>Hello world!</strong>",
"__html": "<b>Hello world!</b>",
}
}
/>
@@ -400,7 +400,7 @@ exports[`post a reply: optimistic response 1`] = `
className="HTMLContent-root"
dangerouslySetInnerHTML={
Object {
"__html": "<strong>Hello world!</strong>",
"__html": "<b>Hello world!</b>",
}
}
/>
@@ -385,7 +385,7 @@ exports[`post a reply: optimistic response 1`] = `
className="HTMLContent-root"
dangerouslySetInnerHTML={
Object {
"__html": "<strong>Hello world!</strong>",
"__html": "<b>Hello world!</b>",
}
}
/>
@@ -33,7 +33,7 @@ beforeEach(() => {
.withArgs(undefined, {
input: {
storyID: stories[0].id,
body: "<strong>Hello world!</strong>",
body: "<b>Hello world!</b>",
clientMutationId: "0",
},
})
@@ -45,7 +45,7 @@ beforeEach(() => {
...baseComment,
id: "comment-x",
author: users[0],
body: "<strong>Hello world! (from server)</strong>",
body: "<b>Hello world! (from server)</b>",
},
},
clientMutationId: "0",
@@ -72,7 +72,7 @@ it("post a comment", async () => {
testRenderer.root
.findByProps({ inputId: "comments-postCommentForm-field" })
.props.onChange({ html: "<strong>Hello world!</strong>" });
.props.onChange({ html: "<b>Hello world!</b>" });
timekeeper.freeze(new Date(baseComment.createdAt));
@@ -90,7 +90,7 @@ it("post a comment", async () => {
// Test for server response.
await waitForElement(() =>
within(within(tabPane).queryAllByTestID(/^comment-/)[0]).getByText(
"<strong>Hello world! (from server)</strong>"
"<b>Hello world! (from server)</b>"
)
);
});
@@ -40,7 +40,7 @@ beforeEach(() => {
storyID: storyWithDeepestReplies.id,
parentID: "comment-with-deepest-replies-5",
parentRevisionID: "revision-0",
body: "<strong>Hello world!</strong>",
body: "<b>Hello world!</b>",
clientMutationId: "0",
},
})
@@ -51,7 +51,7 @@ beforeEach(() => {
...baseComment,
id: "comment-x",
author: users[0],
body: "<strong>Hello world! (from server)</strong>",
body: "<b>Hello world! (from server)</b>",
},
},
clientMutationId: "0",
@@ -103,7 +103,7 @@ it("post a reply", async () => {
.findByProps({
inputId: "comments-replyCommentForm-rte-comment-with-deepest-replies-5",
})
.props.onChange({ html: "<strong>Hello world!</strong>" });
.props.onChange({ html: "<b>Hello world!</b>" });
timekeeper.freeze(new Date(baseComment.createdAt));
form.props.onSubmit();
@@ -35,7 +35,7 @@ beforeEach(() => {
storyID: stories[0].id,
parentID: stories[0].comments.edges[0].node.id,
parentRevisionID: stories[0].comments.edges[0].node.revision.id,
body: "<strong>Hello world!</strong>",
body: "<b>Hello world!</b>",
clientMutationId: "0",
},
})
@@ -46,7 +46,7 @@ beforeEach(() => {
...baseComment,
id: "comment-x",
author: users[0],
body: "<strong>Hello world! (from server)</strong>",
body: "<b>Hello world! (from server)</b>",
},
},
clientMutationId: "0",
@@ -84,7 +84,7 @@ it("post a reply", async () => {
// Write reply .
testRenderer.root
.findByProps({ inputId: "comments-replyCommentForm-rte-comment-0" })
.props.onChange({ html: "<strong>Hello world!</strong>" });
.props.onChange({ html: "<b>Hello world!</b>" });
timekeeper.freeze(new Date(baseComment.createdAt));
form.props.onSubmit();
+6
View File
@@ -44,3 +44,9 @@ it("allows anchor tags and counts them correctly", () => {
expect(body).toMatchSnapshot();
expect(linkCount).toEqual(2);
});
it("allows bolded tags", () => {
const input = "A <b>bolded comment!</b>";
const { body } = sanitizeCommentBody(DOMPurify, input);
expect(body).toEqual(input);
});
+1 -1
View File
@@ -11,7 +11,7 @@ export function createPurify<T extends boolean = true>(
purify.setConfig({
// Only forward anchor tags, bold, italics, blockquote, breaks, divs, and
// spans.
ALLOWED_TAGS: ["a", "strong", "i", "blockquote", "br", "div", "span"],
ALLOWED_TAGS: ["a", "b", "i", "blockquote", "br", "div", "span"],
// Only allow href tags for anchor tags.
ALLOWED_ATTR: ["href"],
// Always return the DOM to the caller of sanitize.