From e04d3b152eeb9c01628955bd0e997ce4b7501276 Mon Sep 17 00:00:00 2001 From: Afshin Darian Date: Fri, 29 Jul 2016 17:19:31 +0100 Subject: [PATCH] Update to v1.13.0 and bug fix: sanitize-html expects tag attributes to be called attribs. (#10360) --- sanitize-html/sanitize-html-tests.ts | 10 +++++++--- sanitize-html/sanitize-html.d.ts | 11 ++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sanitize-html/sanitize-html-tests.ts b/sanitize-html/sanitize-html-tests.ts index eabdcd5a40..8dddc010d2 100644 --- a/sanitize-html/sanitize-html-tests.ts +++ b/sanitize-html/sanitize-html-tests.ts @@ -10,11 +10,15 @@ let options: sanitize.IOptions = { }, transformTags: { 'a': sanitize.simpleTransform('a', { 'rel': 'nofollow' }), - 'img': 'canvas' + 'img': (tagName: string, attribs: sanitize.Attributes) => { + let img = { tagName, attribs }; + img.attribs['alt'] = 'transformed' ; + return img; + } }, exclusiveFilter: function(frame: sanitize.IFrame) { - return frame.tag === 'a' && !frame.text.trim(); - } + return frame.tag === 'a' && !frame.text.trim(); + } }; let unsafe = '
'; diff --git a/sanitize-html/sanitize-html.d.ts b/sanitize-html/sanitize-html.d.ts index 79ee44b15d..a2f27430fe 100644 --- a/sanitize-html/sanitize-html.d.ts +++ b/sanitize-html/sanitize-html.d.ts @@ -1,4 +1,4 @@ -// Type definitions for sanitize-html 1.12.0 +// Type definitions for sanitize-html 1.13.0 // Project: https://github.com/punkave/sanitize-html // Definitions by: Rogier Schouten , Afshin Darian // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -11,10 +11,10 @@ declare namespace sanitize { type Attributes = { [attr: string]: string }; - type Tag = { tagName: string; attributes: Attributes; }; + type Tag = { tagName: string; attribs: Attributes; text?: string; }; - type Transformer = (tagName: string, attributes: Attributes) => Tag; + type Transformer = (tagName: string, attribs: Attributes) => Tag; interface IDefaults { @@ -28,7 +28,7 @@ declare namespace sanitize { interface IFrame { tag: string; - attributes: { [index: string]: string }; + attribs: { [index: string]: string }; text: string; tagPosition: number; } @@ -40,6 +40,7 @@ declare namespace sanitize { allowedSchemes?: string[]; allowedTags?: string[]; exclusiveFilter?: (frame: IFrame) => boolean; + nonTextTags?: string[]; selfClosing?: string[]; transformTags?: { [tagName: string]: string | Transformer }; } @@ -48,7 +49,7 @@ declare namespace sanitize { var defaults: IDefaults; - function simpleTransform(tagName: string, attributes: Attributes, merge?: boolean): Transformer; + function simpleTransform(tagName: string, attribs: Attributes, merge?: boolean): Transformer; }