@@ -226,42 +226,57 @@ describe('HTML', function() {
226
226
expectHTML ( false ) . toBe ( 'false' ) ;
227
227
} ) ;
228
228
229
- it ( 'should accept SVG tags' , function ( ) {
229
+ it ( 'should strip svg elements if not enabled via provider' , 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 ( '' ) ;
232
+ } ) ;
233
+
234
+
235
+ describe ( 'SVG support' , function ( ) {
236
+
237
+ beforeEach ( module ( function ( $sanitizeProvider ) {
238
+ $sanitizeProvider . enableSvg ( true ) ;
239
+ } ) ) ;
240
+
241
+
242
+ it ( 'should accept SVG tags' , function ( ) {
230
243
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
244
. 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>' ) ;
232
- } ) ;
245
+ } ) ;
233
246
234
- it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
235
- expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
247
+ it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
248
+ expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
236
249
. toEqual ( '<svg preserveAspectRatio="true"></svg>' ) ;
237
250
238
- } ) ;
251
+ } ) ;
239
252
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>' )
253
+ it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
254
+ 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
255
. toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
243
256
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>' )
257
+ 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
258
. 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
- } ) ;
259
+ } ) ;
247
260
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>' ) ;
261
+ it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
262
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
263
+ . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
251
264
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
- } ) ;
265
+ 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>' )
266
+ . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
267
+ } ) ;
255
268
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>' ) ;
269
+ it ( 'should not accept SVG animation tags' , function ( ) {
270
+ 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>' )
271
+ . toEqual ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ) ;
259
272
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>' ) ;
273
+ expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
274
+ '<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
275
+ . toEqual ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ) ;
276
+ } ) ;
263
277
} ) ;
264
278
279
+
265
280
describe ( 'htmlSanitizerWriter' , function ( ) {
266
281
/* global htmlSanitizeWriter: false */
267
282
if ( angular . isUndefined ( window . htmlSanitizeWriter ) ) return ;
0 commit comments