@@ -112,7 +112,8 @@ describe('HTML', function() {
112
112
// THESE TESTS ARE EXECUTED WITH COMPILED ANGULAR
113
113
it ( 'should echo html' , function ( ) {
114
114
expectHTML ( 'hello<b class="1\'23" align=\'""\'>world</b>.' ) .
115
- toEqual ( 'hello<b class="1\'23" align="""">world</b>.' ) ;
115
+ toBeOneOf ( 'hello<b class="1\'23" align="""">world</b>.' ,
116
+ 'hello<b align="""" class="1\'23">world</b>.' ) ;
116
117
} ) ;
117
118
118
119
it ( 'should remove script' , function ( ) {
@@ -192,7 +193,8 @@ describe('HTML', function() {
192
193
193
194
it ( 'should ignore back slash as escape' , function ( ) {
194
195
expectHTML ( '<img alt="xxx\\" title="><script>....">' ) .
195
- toEqual ( '<img alt="xxx\\" title="><script>....">' ) ;
196
+ toBeOneOf ( '<img alt="xxx\\" title="><script>....">' ,
197
+ '<img title="><script>...." alt="xxx\\">' ) ;
196
198
} ) ;
197
199
198
200
it ( 'should ignore object attributes' , function ( ) {
@@ -226,42 +228,63 @@ describe('HTML', function() {
226
228
expectHTML ( false ) . toBe ( 'false' ) ;
227
229
} ) ;
228
230
229
- it ( 'should accept SVG tags ' , function ( ) {
230
- expectHTML ( '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></svg>' )
231
- . toEqual ( '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></circle></svg> ' ) ;
231
+ it ( 'should strip svg elements if not enabled via provider ' , function ( ) {
232
+ expectHTML ( '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></svg>' )
233
+ . toEqual ( '' ) ;
232
234
} ) ;
233
235
234
- it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
235
- expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
236
+
237
+ describe ( 'SVG support' , function ( ) {
238
+
239
+ beforeEach ( module ( function ( $sanitizeProvider ) {
240
+ $sanitizeProvider . enableSvg ( true ) ;
241
+ } ) ) ;
242
+
243
+
244
+ it ( 'should accept SVG tags' , function ( ) {
245
+ expectHTML ( '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></svg>' )
246
+ . toBeOneOf ( '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></circle></svg>' ,
247
+ '<svg xmlns="http://www.w3.org/2000/svg" height="150px" width="400px"><circle fill="red" stroke-width="3" stroke="black" r="40" cy="50" cx="50"></circle></svg>' ) ;
248
+ } ) ;
249
+
250
+ it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
251
+ expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
236
252
. toEqual ( '<svg preserveAspectRatio="true"></svg>' ) ;
237
253
238
- } ) ;
254
+ } ) ;
239
255
240
- it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
241
- expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>' )
242
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
256
+ it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
257
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>' )
258
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
259
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
243
260
244
- expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="https://example.com"></a></svg>' )
245
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="https://example.com"></a></svg>' ) ;
246
- } ) ;
261
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="https://example.com"></a></svg>' )
262
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="https://example.com"></a></svg>' ,
263
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a xlink:href="https://example.com"></a></svg>' ) ;
264
+ } ) ;
247
265
248
- it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
249
- expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
250
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
266
+ it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
267
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
268
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
269
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
251
270
252
- expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:bar="https://example.com"></a></svg>' )
253
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
254
- } ) ;
271
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:bar="https://example.com"></a></svg>' )
272
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
273
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
274
+ } ) ;
255
275
256
- it ( 'should not accept SVG animation tags' , function ( ) {
257
- expectHTML ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text><animate attributeName="xlink:href" values="javascript:alert(1)"/></a></svg>' )
258
- . toEqual ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ) ;
276
+ it ( 'should not accept SVG animation tags' , function ( ) {
277
+ expectHTML ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text><animate attributeName="xlink:href" values="javascript:alert(1)"/></a></svg>' )
278
+ . toEqual ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ) ;
259
279
260
- expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
261
- '<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
262
- . toEqual ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ) ;
280
+ expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
281
+ '<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
282
+ . toBeOneOf ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ,
283
+ '<svg><a xlink:href="?" xmlns:xlink="http://www.w3.org/1999/xlink"><circle r="400"></circle></a></svg>' ) ;
284
+ } ) ;
263
285
} ) ;
264
286
287
+
265
288
describe ( 'htmlSanitizerWriter' , function ( ) {
266
289
/* global htmlSanitizeWriter: false */
267
290
if ( angular . isUndefined ( window . htmlSanitizeWriter ) ) return ;
0 commit comments