2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-30 18:07:40 -07:00
|
|
|
import {ElementSchemaRegistry} from '@angular/compiler';
|
2016-07-25 03:02:57 -07:00
|
|
|
import {SchemaMetadata, SecurityContext} from '@angular/core';
|
2015-09-14 15:59:09 -07:00
|
|
|
|
|
|
|
|
export class MockSchemaRegistry implements ElementSchemaRegistry {
|
2016-06-08 16:38:52 -07:00
|
|
|
constructor(
|
|
|
|
|
public existingProperties: {[key: string]: boolean},
|
2016-08-23 10:52:40 -07:00
|
|
|
public attrPropMapping: {[key: string]: string},
|
2016-09-28 02:10:02 +02:00
|
|
|
public existingElements: {[key: string]: boolean}, public invalidProperties: Array<string>,
|
|
|
|
|
public invalidAttributes: Array<string>) {}
|
2016-04-28 17:50:03 -07:00
|
|
|
|
2016-07-25 03:02:57 -07:00
|
|
|
hasProperty(tagName: string, property: string, schemas: SchemaMetadata[]): boolean {
|
2016-08-23 10:52:40 -07:00
|
|
|
const value = this.existingProperties[property];
|
|
|
|
|
return value === void 0 ? true : value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hasElement(tagName: string, schemaMetas: SchemaMetadata[]): boolean {
|
|
|
|
|
const value = this.existingElements[tagName.toLowerCase()];
|
|
|
|
|
return value === void 0 ? true : value;
|
2015-09-14 15:59:09 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 16:04:08 -07:00
|
|
|
securityContext(tagName: string, property: string): SecurityContext {
|
|
|
|
|
return SecurityContext.NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 10:52:40 -07:00
|
|
|
getMappedPropName(attrName: string): string { return this.attrPropMapping[attrName] || attrName; }
|
2016-07-28 19:39:10 +02:00
|
|
|
|
|
|
|
|
getDefaultComponentElementName(): string { return 'ng-component'; }
|
2016-09-28 02:10:02 +02:00
|
|
|
|
|
|
|
|
validateProperty(name: string): {error: boolean, msg?: string} {
|
|
|
|
|
if (this.invalidProperties.indexOf(name) > -1) {
|
|
|
|
|
return {error: true, msg: `Binding to property '${name}' is disallowed for security reasons`};
|
|
|
|
|
} else {
|
|
|
|
|
return {error: false};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validateAttribute(name: string): {error: boolean, msg?: string} {
|
|
|
|
|
if (this.invalidAttributes.indexOf(name) > -1) {
|
|
|
|
|
return {
|
|
|
|
|
error: true,
|
|
|
|
|
msg: `Binding to attribute '${name}' is disallowed for security reasons`
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {error: false};
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-02 09:30:36 -07:00
|
|
|
}
|