mirror of
https://github.com/wassname/talk.git
synced 2026-08-09 12:30:42 +08:00
Version Bumps (#2677)
* chore: upgraded versions * chore: linting * fix: updated snap
This commit is contained in:
@@ -16,7 +16,8 @@ exports[`sanitizes evil html 1`] = `
|
||||
className="HTMLContent-root"
|
||||
dangerouslySetInnerHTML={
|
||||
Object {
|
||||
"__html": "<span>Hello world</span>
|
||||
"__html": "
|
||||
<span>Hello world</span>
|
||||
",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ Object {
|
||||
`;
|
||||
|
||||
exports[`allows anchor tags and counts them correctly 1`] = `
|
||||
"<div>
|
||||
"
|
||||
<div>
|
||||
<a href=\\"https://mozilla.org/\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">https://mozilla.org/</a>
|
||||
<a href=\\"https://mozilla.org/\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">https://mozilla.org/</a>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import newDOMPurify, { DOMPurify } from "dompurify";
|
||||
import createDOMPurify from "dompurify";
|
||||
|
||||
export function createPurify<T extends boolean = true>(
|
||||
window: Window,
|
||||
returnDOM: T = true as T
|
||||
) {
|
||||
type DOMPurify = ReturnType<typeof createDOMPurify>;
|
||||
|
||||
export function createPurify(window: Window, returnDOM = true) {
|
||||
// Initializing JSDOM and DOMPurify
|
||||
const purify = newDOMPurify<T>(window);
|
||||
const purify = createDOMPurify(window);
|
||||
|
||||
// Setting our DOMPurify config.
|
||||
purify.setConfig({
|
||||
@@ -42,7 +41,7 @@ export function createPurify<T extends boolean = true>(
|
||||
|
||||
export function sanitizeCommentBody(purify: DOMPurify, source: string) {
|
||||
// Sanitize and return the HTMLBodyElement for the parsed source.
|
||||
const sanitized = purify.sanitize(source);
|
||||
const sanitized = purify.sanitize(source, { RETURN_DOM: true });
|
||||
|
||||
// Count the total number of anchor links in the sanitized output, this is the
|
||||
// number of links.
|
||||
|
||||
@@ -55,7 +55,7 @@ export const countHandler = ({ mongo, i18n }: CountOptions): RequestHandler => {
|
||||
}
|
||||
);
|
||||
// Strip dangerous html from translation.
|
||||
html = DOMPurify.sanitize(html) as string;
|
||||
html = DOMPurify.sanitize(html);
|
||||
}
|
||||
|
||||
// Respond using jsonp.
|
||||
|
||||
@@ -130,7 +130,7 @@ function createMessageTranslator(i18n: I18n) {
|
||||
}
|
||||
|
||||
// Configure the purification.
|
||||
const purify = createDOMPurify<false>(dom.window);
|
||||
const purify = createDOMPurify(dom.window);
|
||||
|
||||
// Strip the l10n attributes from the email HTML.
|
||||
purify.sanitize(dom.window.document.documentElement, {
|
||||
|
||||
Vendored
-28
@@ -1,28 +0,0 @@
|
||||
declare module "dompurify" {
|
||||
interface Config<T extends boolean> {
|
||||
ADD_TAGS?: string[];
|
||||
ALLOWED_ATTR?: string[];
|
||||
ALLOWED_TAGS?: string[];
|
||||
FORBID_TAGS?: string[];
|
||||
FORBID_ATTR?: string[];
|
||||
RETURN_DOM?: boolean;
|
||||
RETURN_DOM_FRAGMENT?: T;
|
||||
ALLOW_DATA_ATTR?: boolean;
|
||||
WHOLE_DOCUMENT?: boolean;
|
||||
SANITIZE_DOM?: boolean;
|
||||
IN_PLACE?: boolean;
|
||||
}
|
||||
|
||||
class DOMPurify<T extends boolean = true> {
|
||||
public setConfig(config: Config<T>): void;
|
||||
public sanitize(
|
||||
source: HTMLElement | string,
|
||||
config?: Config<T>
|
||||
): T extends true ? HTMLBodyElement : string;
|
||||
public addHook(name: string, callback: (node: Element) => void): void;
|
||||
}
|
||||
|
||||
export default function createDOMPurify<T extends boolean>(
|
||||
window: any
|
||||
): DOMPurify<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user