From 607b7f1b4eecf02383abde149b113de89be10ea6 Mon Sep 17 00:00:00 2001 From: JoelWee <32009741+JoelWee@users.noreply.github.com> Date: Tue, 30 Jun 2020 18:10:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#45796=20[sanitize-?= =?UTF-8?q?html]=20fix=20IOptions["allowedClasses"]=20type=20by=20@JoelWee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The source code does not support setting boolean to allowedClasses. It only supports this for individual tags in allowedClasses. E.g. { p: false } will allow all classes for the p tag. --- types/sanitize-html/index.d.ts | 2 +- types/sanitize-html/sanitize-html-tests.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/types/sanitize-html/index.d.ts b/types/sanitize-html/index.d.ts index 5e5e9ab2a3..5584eada56 100644 --- a/types/sanitize-html/index.d.ts +++ b/types/sanitize-html/index.d.ts @@ -57,7 +57,7 @@ declare namespace sanitize { interface IOptions { allowedAttributes?: { [index: string]: AllowedAttribute[] } | boolean; allowedStyles?: { [index: string]: { [index: string]: RegExp[] } }; - allowedClasses?: { [index: string]: string[] } | boolean; + allowedClasses?: { [index: string]: string[] | boolean }; allowedIframeHostnames?: string[]; allowIframeRelativeUrls?: boolean; allowedSchemes?: string[] | boolean; diff --git a/types/sanitize-html/sanitize-html-tests.ts b/types/sanitize-html/sanitize-html-tests.ts index ef6741c9cb..2f1126b389 100644 --- a/types/sanitize-html/sanitize-html-tests.ts +++ b/types/sanitize-html/sanitize-html-tests.ts @@ -6,6 +6,10 @@ let options: sanitize.IOptions = { 'a': sanitize.defaults.allowedAttributes['a'].concat('rel'), 'img': ['src', 'height', 'width', 'alt', 'style'] }, + allowedClasses: { + a: ['className'], + p: false, + }, allowedStyles: { '*': { color: [/^red$/],