revert: refactor(ivy): remove styleSanitizer instruction in favor of an inline param (#34480) (#34910)
This reverts commit 84d24c08e1
.
PR Close #34910
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
import {NgForOfContext} from '@angular/common';
|
||||
|
||||
import {ɵɵdefineComponent} from '../../src/render3/definition';
|
||||
import {RenderFlags, ɵɵattribute, ɵɵclassMap, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵproperty, ɵɵselect, ɵɵstyleMap, ɵɵstyleProp, ɵɵtemplate, ɵɵtext, ɵɵtextInterpolate1} from '../../src/render3/index';
|
||||
import {RenderFlags, ɵɵattribute, ɵɵclassMap, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵproperty, ɵɵselect, ɵɵstyleMap, ɵɵstyleProp, ɵɵstyleSanitizer, ɵɵtemplate, ɵɵtext, ɵɵtextInterpolate1} from '../../src/render3/index';
|
||||
import {AttributeMarker} from '../../src/render3/interfaces/node';
|
||||
import {bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl, getSanitizationBypassType, unwrapSafeValue} from '../../src/sanitization/bypass';
|
||||
import {ɵɵdefaultStyleSanitizer, ɵɵsanitizeHtml, ɵɵsanitizeResourceUrl, ɵɵsanitizeScript, ɵɵsanitizeStyle, ɵɵsanitizeUrl} from '../../src/sanitization/sanitization';
|
||||
@ -137,22 +137,20 @@ describe('instructions', () => {
|
||||
|
||||
describe('styleProp', () => {
|
||||
it('should automatically sanitize unless a bypass operation is applied', () => {
|
||||
const t = new TemplateFixture(
|
||||
() => { return createDiv(); },
|
||||
() => {
|
||||
ɵɵstyleProp('background-image', 'url("http://server")', ɵɵdefaultStyleSanitizer);
|
||||
},
|
||||
1);
|
||||
|
||||
const element = t.hostElement.firstChild as HTMLElement;
|
||||
expect(element.style.getPropertyValue('background-image')).toEqual('');
|
||||
const t = new TemplateFixture(() => { return createDiv(); }, () => {}, 1);
|
||||
t.update(() => {
|
||||
ɵɵstyleSanitizer(ɵɵdefaultStyleSanitizer);
|
||||
ɵɵstyleProp('background-image', 'url("http://server")');
|
||||
});
|
||||
// nothing is set because sanitizer suppresses it.
|
||||
expect(t.html).toEqual('<div></div>');
|
||||
|
||||
t.update(() => {
|
||||
ɵɵstyleProp(
|
||||
'background-image', bypassSanitizationTrustStyle('url("http://server2")'),
|
||||
ɵɵdefaultStyleSanitizer);
|
||||
ɵɵstyleSanitizer(ɵɵdefaultStyleSanitizer);
|
||||
ɵɵstyleProp('background-image', bypassSanitizationTrustStyle('url("http://server2")'));
|
||||
});
|
||||
expect(element.style.getPropertyValue('background-image')).toEqual('url("http://server2")');
|
||||
expect((t.hostElement.firstChild as HTMLElement).style.getPropertyValue('background-image'))
|
||||
.toEqual('url("http://server2")');
|
||||
});
|
||||
});
|
||||
|
||||
@ -162,14 +160,10 @@ describe('instructions', () => {
|
||||
function createDivWithStyle() { ɵɵelement(0, 'div', 0); }
|
||||
|
||||
it('should add style', () => {
|
||||
const fixture = new TemplateFixture(createDivWithStyle, () => {
|
||||
ɵɵstyleMap({'background-color': 'red'});
|
||||
}, 1, 0, null, null, null, undefined, attrs);
|
||||
fixture.update();
|
||||
const targetDiv = fixture.hostElement.querySelector('div') !;
|
||||
const style = targetDiv.style as{[key: string]: any};
|
||||
expect(style['background-color']).toEqual('red');
|
||||
expect(style['height']).toEqual('10px');
|
||||
const fixture = new TemplateFixture(
|
||||
createDivWithStyle, () => {}, 1, 0, null, null, null, undefined, attrs);
|
||||
fixture.update(() => { ɵɵstyleMap({'background-color': 'red'}); });
|
||||
expect(fixture.html).toEqual('<div style="background-color: red; height: 10px;"></div>');
|
||||
});
|
||||
|
||||
it('should sanitize new styles that may contain `url` properties', () => {
|
||||
@ -179,6 +173,7 @@ describe('instructions', () => {
|
||||
const fixture = new TemplateFixture(
|
||||
() => { return createDiv(); }, //
|
||||
() => {
|
||||
ɵɵstyleSanitizer(sanitizerInterceptor.getStyleSanitizer());
|
||||
ɵɵstyleMap({
|
||||
'background-image': 'background-image',
|
||||
'background': 'background',
|
||||
|
Reference in New Issue
Block a user