refactor(ivy): enable sanitization support for the new styling algorithm (#30667)

This patch is one of the final patches to refactor the styling algorithm
to be more efficient, performant and less complex.

This patch enables sanitization support for map-based and prop-based
style bindings.

PR Close #30667
This commit is contained in:
Matias Niemelä
2019-05-24 13:49:57 -07:00
parent d72479b628
commit 82682bb93f
23 changed files with 725 additions and 102 deletions

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {StyleSanitizeFn} from '../../sanitization/style_sanitizer';
import {StyleSanitizeFn, StyleSanitizeMode} from '../../sanitization/style_sanitizer';
import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty';
import {AttributeMarker, TAttributes} from '../interfaces/node';
import {BindingStore, BindingType, Player, PlayerBuilder, PlayerFactory, PlayerIndex} from '../interfaces/player';
@ -943,7 +943,9 @@ function updateSingleStylingValue(
if (currDirective !== directiveIndex) {
const prop = getProp(context, singleIndex);
const sanitizer = getStyleSanitizer(context, directiveIndex);
setSanitizeFlag(context, singleIndex, (sanitizer && sanitizer(prop)) ? true : false);
setSanitizeFlag(
context, singleIndex,
(sanitizer && sanitizer(prop, null, StyleSanitizeMode.ValidateProperty)) ? true : false);
}
// the value will always get updated (even if the dirty flag is skipped)
@ -1141,7 +1143,8 @@ export function setStyle(
native: any, prop: string, value: string | null, renderer: Renderer3,
sanitizer: StyleSanitizeFn | null, store?: BindingStore | null,
playerBuilder?: ClassAndStylePlayerBuilder<any>| null) {
value = sanitizer && value ? sanitizer(prop, value) : value;
value =
sanitizer && value ? sanitizer(prop, value, StyleSanitizeMode.ValidateAndSanitize) : value;
if (store || playerBuilder) {
if (store) {
store.setValue(prop, value);
@ -1461,7 +1464,9 @@ function valueExists(value: string | null | boolean, isClassBased?: boolean) {
function prepareInitialFlag(
context: StylingContext, prop: string, entryIsClassBased: boolean,
sanitizer?: StyleSanitizeFn | null) {
let flag = (sanitizer && sanitizer(prop)) ? StylingFlags.Sanitize : StylingFlags.None;
let flag = (sanitizer && sanitizer(prop, null, StyleSanitizeMode.ValidateProperty)) ?
StylingFlags.Sanitize :
StylingFlags.None;
let initialIndex: number;
if (entryIsClassBased) {