fix(DomSchemaRegistry): detect invalid elements

This commit is contained in:
Victor Berchet
2016-08-23 10:52:40 -07:00
parent 2b20db6c5a
commit 1df69cb4d2
22 changed files with 638 additions and 395 deletions

View File

@ -8,27 +8,29 @@
import {ElementSchemaRegistry} from '@angular/compiler';
import {SchemaMetadata, SecurityContext} from '@angular/core';
import {isPresent} from './facade/lang';
import {ElementSchemaRegistry} from '../index';
export class MockSchemaRegistry implements ElementSchemaRegistry {
constructor(
public existingProperties: {[key: string]: boolean},
public attrPropMapping: {[key: string]: string}) {}
public attrPropMapping: {[key: string]: string},
public existingElements: {[key: string]: boolean}) {}
hasProperty(tagName: string, property: string, schemas: SchemaMetadata[]): boolean {
var result = this.existingProperties[property];
return isPresent(result) ? result : true;
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;
}
securityContext(tagName: string, property: string): SecurityContext {
return SecurityContext.NONE;
}
getMappedPropName(attrName: string): string {
var result = this.attrPropMapping[attrName];
return isPresent(result) ? result : attrName;
}
getMappedPropName(attrName: string): string { return this.attrPropMapping[attrName] || attrName; }
getDefaultComponentElementName(): string { return 'ng-component'; }
}

View File

@ -19,7 +19,7 @@ export function createUrlResolverWithoutPackagePrefix(): UrlResolver {
// internal test packages.
// TODO: get rid of it or move to a separate @angular/internal_testing package
export var TEST_COMPILER_PROVIDERS: Provider[] = [
{provide: ElementSchemaRegistry, useValue: new MockSchemaRegistry({}, {})},
{provide: ElementSchemaRegistry, useValue: new MockSchemaRegistry({}, {}, {})},
{provide: ResourceLoader, useClass: MockResourceLoader},
{provide: UrlResolver, useFactory: createUrlResolverWithoutPackagePrefix}
];