9
9
import { NgForOfContext } from '@angular/common' ;
10
10
11
11
import { ɵɵdefineComponent } from '../../src/render3/definition' ;
12
- import { RenderFlags , ɵɵbind , ɵɵclassMap , ɵɵelement , ɵɵelementAttribute , ɵɵelementEnd , ɵɵelementProperty , ɵɵelementStart , ɵɵinterpolation1 , ɵɵproperty , ɵɵselect , ɵɵstyleMap , ɵɵstyleProp , ɵɵstyling , ɵɵstylingApply , ɵɵtemplate , ɵɵtext , ɵɵtextBinding } from '../../src/render3/index' ;
12
+ import { RenderFlags , ɵɵbind , ɵɵclassMap , ɵɵelement , ɵɵelementAttribute , ɵɵelementEnd , ɵɵelementStart , ɵɵinterpolation1 , ɵɵproperty , ɵɵselect , ɵɵstyleMap , ɵɵstyleProp , ɵɵstyling , ɵɵstylingApply , ɵɵtemplate , ɵɵtext , ɵɵtextBinding } from '../../src/render3/index' ;
13
13
import { AttributeMarker } from '../../src/render3/interfaces/node' ;
14
14
import { bypassSanitizationTrustHtml , bypassSanitizationTrustResourceUrl , bypassSanitizationTrustScript , bypassSanitizationTrustStyle , bypassSanitizationTrustUrl } from '../../src/sanitization/bypass' ;
15
15
import { ɵɵdefaultStyleSanitizer , ɵɵsanitizeHtml , ɵɵsanitizeResourceUrl , ɵɵsanitizeScript , ɵɵsanitizeStyle , ɵɵsanitizeUrl } from '../../src/sanitization/sanitization' ;
@@ -58,10 +58,16 @@ describe('instructions', () => {
58
58
it ( 'should update bindings when value changes with the correct perf counters' , ( ) => {
59
59
const t = new TemplateFixture ( createAnchor , ( ) => { } , 1 , 1 ) ;
60
60
61
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'title' , ɵɵbind ( 'Hello' ) ) ) ;
61
+ t . update ( ( ) => {
62
+ ɵɵselect ( 0 ) ;
63
+ ɵɵproperty ( 'title' , 'Hello' ) ;
64
+ } ) ;
62
65
expect ( t . html ) . toEqual ( '<a title="Hello"></a>' ) ;
63
66
64
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'title' , ɵɵbind ( 'World' ) ) ) ;
67
+ t . update ( ( ) => {
68
+ ɵɵselect ( 0 ) ;
69
+ ɵɵproperty ( 'title' , 'World' ) ;
70
+ } ) ;
65
71
expect ( t . html ) . toEqual ( '<a title="World"></a>' ) ;
66
72
expect ( ngDevMode ) . toHaveProperties ( {
67
73
firstTemplatePass : 1 ,
@@ -74,7 +80,10 @@ describe('instructions', () => {
74
80
75
81
it ( 'should not update bindings when value does not change, with the correct perf counters' ,
76
82
( ) => {
77
- const idempotentUpdate = ( ) => ɵɵelementProperty ( 0 , 'title' , ɵɵbind ( 'Hello' ) ) ;
83
+ const idempotentUpdate = ( ) => {
84
+ ɵɵselect ( 0 ) ;
85
+ ɵɵproperty ( 'title' , 'Hello' ) ;
86
+ } ;
78
87
const t = new TemplateFixture ( createAnchor , idempotentUpdate , 1 , 1 ) ;
79
88
80
89
t . update ( ) ;
@@ -295,7 +304,8 @@ describe('instructions', () => {
295
304
}
296
305
if ( rf & RenderFlags . Update ) {
297
306
const row_r2 = ctx0 . $implicit ;
298
- ɵɵelementProperty ( 1 , 'ngForOf' , ɵɵbind ( row_r2 ) ) ;
307
+ ɵɵselect ( 1 ) ;
308
+ ɵɵproperty ( 'ngForOf' , row_r2 ) ;
299
309
}
300
310
}
301
311
@@ -331,7 +341,8 @@ describe('instructions', () => {
331
341
ɵɵtemplate ( 0 , ToDoAppComponent_NgForOf_Template_0 , 2 , 1 , 'ul' , _c0 ) ;
332
342
}
333
343
if ( rf & RenderFlags . Update ) {
334
- ɵɵelementProperty ( 0 , 'ngForOf' , ɵɵbind ( ctx . rows ) ) ;
344
+ ɵɵselect ( 0 ) ;
345
+ ɵɵproperty ( 'ngForOf' , ctx . rows ) ;
335
346
}
336
347
} ,
337
348
directives : [ NgForOf ]
@@ -448,66 +459,84 @@ describe('instructions', () => {
448
459
449
460
it ( 'should work for script sanitization' , ( ) => {
450
461
const s = new LocalMockSanitizer ( value => `${ value } //sanitized` ) ;
451
- const t = new TemplateFixture ( createScript , undefined , 1 , 0 , null , null , s ) ;
462
+ const t = new TemplateFixture ( createScript , undefined , 1 , 1 , null , null , s ) ;
452
463
const inputValue = 'fn();' ;
453
464
const outputValue = 'fn(); //sanitized' ;
454
465
455
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'innerHTML' , inputValue , ɵɵsanitizeScript ) ) ;
466
+ t . update ( ( ) => {
467
+ ɵɵselect ( 0 ) ;
468
+ ɵɵproperty ( 'innerHTML' , inputValue , ɵɵsanitizeScript ) ;
469
+ } ) ;
456
470
expect ( t . html ) . toEqual ( `<script>${ outputValue } </script>` ) ;
457
471
expect ( s . lastSanitizedValue ) . toEqual ( outputValue ) ;
458
472
} ) ;
459
473
460
474
it ( 'should bypass script sanitization if marked by the service' , ( ) => {
461
475
const s = new LocalMockSanitizer ( value => '' ) ;
462
- const t = new TemplateFixture ( createScript , undefined , 1 , 0 , null , null , s ) ;
476
+ const t = new TemplateFixture ( createScript , undefined , 1 , 1 , null , null , s ) ;
463
477
const inputValue = s . bypassSecurityTrustScript ( 'alert("bar")' ) ;
464
478
const outputValue = 'alert("bar")' ;
465
479
466
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'innerHTML' , inputValue , ɵɵsanitizeScript ) ) ;
480
+ t . update ( ( ) => {
481
+ ɵɵselect ( 0 ) ;
482
+ ɵɵproperty ( 'innerHTML' , inputValue , ɵɵsanitizeScript ) ;
483
+ } ) ;
467
484
expect ( t . html ) . toEqual ( `<script>${ outputValue } </script>` ) ;
468
485
expect ( s . lastSanitizedValue ) . toBeFalsy ( ) ;
469
486
} ) ;
470
487
471
488
it ( 'should bypass ivy-level script sanitization if a custom sanitizer is used' , ( ) => {
472
489
const s = new LocalMockSanitizer ( value => '' ) ;
473
- const t = new TemplateFixture ( createScript , undefined , 1 , 0 , null , null , s ) ;
490
+ const t = new TemplateFixture ( createScript , undefined , 1 , 1 , null , null , s ) ;
474
491
const inputValue = bypassSanitizationTrustScript ( 'alert("bar")' ) ;
475
492
const outputValue = 'alert("bar")-ivy' ;
476
493
477
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'innerHTML' , inputValue , ɵɵsanitizeScript ) ) ;
494
+ t . update ( ( ) => {
495
+ ɵɵselect ( 0 ) ;
496
+ ɵɵproperty ( 'innerHTML' , inputValue , ɵɵsanitizeScript ) ;
497
+ } ) ;
478
498
expect ( t . html ) . toEqual ( `<script>${ outputValue } </script>` ) ;
479
499
expect ( s . lastSanitizedValue ) . toBeFalsy ( ) ;
480
500
} ) ;
481
501
482
502
it ( 'should work for html sanitization' , ( ) => {
483
503
const s = new LocalMockSanitizer ( value => `${ value } <!--sanitized-->` ) ;
484
- const t = new TemplateFixture ( createDiv , undefined , 1 , 0 , null , null , s ) ;
504
+ const t = new TemplateFixture ( createDiv , undefined , 1 , 1 , null , null , s ) ;
485
505
const inputValue = '<header></header>' ;
486
506
const outputValue = '<header></header> <!--sanitized-->' ;
487
507
488
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'innerHTML' , inputValue , ɵɵsanitizeHtml ) ) ;
508
+ t . update ( ( ) => {
509
+ ɵɵselect ( 0 ) ;
510
+ ɵɵproperty ( 'innerHTML' , inputValue , ɵɵsanitizeHtml ) ;
511
+ } ) ;
489
512
expect ( t . html ) . toEqual ( `<div>${ outputValue } </div>` ) ;
490
513
expect ( s . lastSanitizedValue ) . toEqual ( outputValue ) ;
491
514
} ) ;
492
515
493
516
it ( 'should bypass html sanitization if marked by the service' , ( ) => {
494
517
const s = new LocalMockSanitizer ( value => '' ) ;
495
- const t = new TemplateFixture ( createDiv , undefined , 1 , 0 , null , null , s ) ;
518
+ const t = new TemplateFixture ( createDiv , undefined , 1 , 1 , null , null , s ) ;
496
519
const inputValue = s . bypassSecurityTrustHtml ( '<div onclick="alert(123)"></div>' ) ;
497
520
const outputValue = '<div onclick="alert(123)"></div>' ;
498
521
499
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'innerHTML' , inputValue , ɵɵsanitizeHtml ) ) ;
522
+ t . update ( ( ) => {
523
+ ɵɵselect ( 0 ) ;
524
+ ɵɵproperty ( 'innerHTML' , inputValue , ɵɵsanitizeHtml ) ;
525
+ } ) ;
500
526
expect ( t . html ) . toEqual ( `<div>${ outputValue } </div>` ) ;
501
527
expect ( s . lastSanitizedValue ) . toBeFalsy ( ) ;
502
528
} ) ;
503
529
504
530
it ( 'should bypass ivy-level script sanitization if a custom sanitizer is used' , ( ) => {
505
531
const s = new LocalMockSanitizer ( value => '' ) ;
506
- const t = new TemplateFixture ( createDiv , undefined , 1 , 0 , null , null , s ) ;
532
+ const t = new TemplateFixture ( createDiv , undefined , 1 , 1 , null , null , s ) ;
507
533
const inputValue = bypassSanitizationTrustHtml ( '<div onclick="alert(123)"></div>' ) ;
508
534
const outputValue = '<div onclick="alert(123)"></div>-ivy' ;
509
535
510
- t . update ( ( ) => ɵɵelementProperty ( 0 , 'innerHTML' , inputValue , ɵɵsanitizeHtml ) ) ;
536
+ t . update ( ( ) => {
537
+ ɵɵselect ( 0 ) ;
538
+ ɵɵproperty ( 'innerHTML' , inputValue , ɵɵsanitizeHtml ) ;
539
+ } ) ;
511
540
expect ( t . html ) . toEqual ( `<div>${ outputValue } </div>` ) ;
512
541
expect ( s . lastSanitizedValue ) . toBeFalsy ( ) ;
513
542
} ) ;
0 commit comments