From 5b053a7579fad0f6ca37345f5fe60547ad16f08a Mon Sep 17 00:00:00 2001 From: bazuzi Date: Tue, 25 Aug 2015 16:44:03 -0400 Subject: [PATCH] Expand typings for DOMPurify - A config can be passed in when using sanitize and the same config object is passed into the addHook callback. - Depending on config options, sanitize may return a DOM Node. - The basic examples from the DOMPurify README will confirm that the config object can be used flexibly with sanitize. --- dompurify/dompurify-tests.ts | 49 ++++++++++++++++++++++++++++++++++++ dompurify/dompurify.d.ts | 23 +++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/dompurify/dompurify-tests.ts b/dompurify/dompurify-tests.ts index d9d6e0bd6..5cc6e067b 100644 --- a/dompurify/dompurify-tests.ts +++ b/dompurify/dompurify-tests.ts @@ -6,3 +6,52 @@ dompurify.sanitize(''); dompurify.addHook('beforeSanitizeElements', (el, data, config) => { return el; }); + +//examples from the DOMPurify README +let dirty = '

Totally safe

Totally not safe

'; + +// allow only +dompurify.sanitize(dirty, {ALLOWED_TAGS: ['b']}); + +// allow only and with style attributes (for whatever reason) +dompurify.sanitize(dirty, {ALLOWED_TAGS: ['b', 'q'], ALLOWED_ATTR: ['style']}); + +// leave all as it is but forbid