@@ -100,7 +100,8 @@ describe('HTML', function() {
100
100
// THESE TESTS ARE EXECUTED WITH COMPILED ANGULAR
101
101
it ( 'should echo html' , function ( ) {
102
102
expectHTML ( 'hello<b class="1\'23" align=\'""\'>world</b>.' ) .
103
- toEqual ( 'hello<b class="1\'23" align="""">world</b>.' ) ;
103
+ toBeOneOf ( 'hello<b class="1\'23" align="""">world</b>.' ,
104
+ 'hello<b align="""" class="1\'23">world</b>.' ) ;
104
105
} ) ;
105
106
106
107
it ( 'should remove script' , function ( ) {
@@ -180,7 +181,8 @@ describe('HTML', function() {
180
181
181
182
it ( 'should ignore back slash as escape' , function ( ) {
182
183
expectHTML ( '<img alt="xxx\\" title="><script>....">' ) .
183
- toEqual ( '<img alt="xxx\\" title="><script>....">' ) ;
184
+ toBeOneOf ( '<img alt="xxx\\" title="><script>....">' ,
185
+ '<img title="><script>...." alt="xxx\\">' ) ;
184
186
} ) ;
185
187
186
188
it ( 'should ignore object attributes' , function ( ) {
@@ -214,42 +216,64 @@ describe('HTML', function() {
214
216
expectHTML ( false ) . toBe ( 'false' ) ;
215
217
} ) ;
216
218
217
- it ( 'should accept SVG tags ' , function ( ) {
218
- 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>' )
219
- . 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> ' ) ;
219
+ it ( 'should strip svg elements if not enabled via provider ' , function ( ) {
220
+ 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>' )
221
+ . toEqual ( '' ) ;
220
222
} ) ;
221
223
222
- it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
223
- expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
224
+
225
+ describe ( 'SVG support' , function ( ) {
226
+
227
+ beforeEach ( module ( function ( $sanitizeProvider ) {
228
+ $sanitizeProvider . enableSvg ( true ) ;
229
+ } ) ) ;
230
+
231
+
232
+ it ( 'should accept SVG tags' , function ( ) {
233
+ 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>' )
234
+ . 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>' ,
235
+ '<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>' ,
236
+ '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle fill="red" stroke="black" stroke-width="3" cx="50" cy="50" r="40"></circle></svg>' ) ;
237
+ } ) ;
238
+
239
+ it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
240
+ expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
224
241
. toEqual ( '<svg preserveAspectRatio="true"></svg>' ) ;
225
242
226
- } ) ;
243
+ } ) ;
227
244
228
- it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
229
- expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>' )
230
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
245
+ it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
246
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>' )
247
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
248
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
231
249
232
- 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>' )
233
- . 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>' ) ;
234
- } ) ;
250
+ 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>' )
251
+ . 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>' ,
252
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a xlink:href="https://example.com"></a></svg>' ) ;
253
+ } ) ;
235
254
236
- it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
237
- expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
238
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
255
+ it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
256
+ expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
257
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
258
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
239
259
240
- 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>' )
241
- . toEqual ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ) ;
242
- } ) ;
260
+ 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>' )
261
+ . toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
262
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
263
+ } ) ;
243
264
244
- it ( 'should not accept SVG animation tags' , function ( ) {
245
- 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>' )
246
- . toEqual ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ) ;
265
+ it ( 'should not accept SVG animation tags' , function ( ) {
266
+ 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>' )
267
+ . toEqual ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ) ;
247
268
248
- expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
249
- '<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
250
- . toEqual ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ) ;
269
+ expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
270
+ '<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
271
+ . toBeOneOf ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ,
272
+ '<svg><a xlink:href="?" xmlns:xlink="http://www.w3.org/1999/xlink"><circle r="400"></circle></a></svg>' ) ;
273
+ } ) ;
251
274
} ) ;
252
275
276
+
253
277
describe ( 'htmlSanitizerWriter' , function ( ) {
254
278
/* global htmlSanitizeWriter: false */
255
279
if ( angular . isUndefined ( window . htmlSanitizeWriter ) ) return ;
0 commit comments