1+ import { sanitizeDOMString } from ".." ;
2+
3+ describe ( 'sanitizeDOMString' , ( ) => {
4+
5+ it ( 'filter onerror' , ( ) => {
6+ expect ( sanitizeDOMString ( '<img src="x" onerror="alert(document.cookie);">' ) )
7+ . toEqual ( '<img src="x">' ) ;
8+ } ) ;
9+
10+ it ( 'filter onclick' , ( ) => {
11+ expect ( sanitizeDOMString ( '<button id="myButton" name="myButton" onclick="alert(document.cookie);">harmless button</button>' ) )
12+ . toEqual ( '<button id="myButton" name="myButton">harmless button</button>' ) ;
13+ } ) ;
14+
15+ it ( 'filter <a> href JS' , ( ) => {
16+ expect ( sanitizeDOMString ( '<a href="javascript:alert(document.cookie)">harmless link</a>' ) )
17+ . toEqual ( '<a>harmless link</a>' ) ;
18+ } ) ;
19+
20+ it ( 'filter <a> href JS + class attribute' , ( ) => {
21+ expect ( sanitizeDOMString ( '<a class="link" href="Javascript:alert(document.cookie)">harmless link</a>' ) )
22+ . toEqual ( '<a class="link">harmless link</a>' ) ;
23+ } ) ;
24+
25+ it ( 'filter <iframe>' , ( ) => {
26+ expect ( sanitizeDOMString ( '<iframe src="javascript:alert(document.cookie)"></iframe>' ) )
27+ . toEqual ( '' ) ;
28+ } ) ;
29+
30+ it ( 'filter href + javascript ' , ( ) => {
31+ expect ( sanitizeDOMString ( '<div><button><a href="javascript:alert(document.cookie)">click me</a></button></div>' ) )
32+ . toEqual ( '<div><button><a>click me</a></button></div>' ) ;
33+ } ) ;
34+
35+ it ( 'filter <object>' , ( ) => {
36+ expect ( sanitizeDOMString ( '<object><img src="x" onerror="alert(document.cookie);"></object>' ) )
37+ . toEqual ( '' ) ;
38+ } ) ;
39+
40+ it ( 'sanitizeDOMString' , ( ) => {
41+ expect ( sanitizeDOMString ( '<ion-item><ion-label>Hello!</ion-label><ion-button onclick="alert(document.cookie);">Click me</ion-button>' ) )
42+ . toEqual ( '<ion-item><ion-label>Hello!</ion-label><ion-button>Click me</ion-button></ion-item>' ) ;
43+ } ) ;
44+ } ) ;
0 commit comments