Skip to content

Commit 866e9cd

Browse files
committed
Upgrade to RC1: Add a SanitizationService implementation.
1 parent 93e8fef commit 866e9cd

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/nativescript-angular/application.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import 'globals';
2-
global.window = global;
32
import "zone.js/dist/zone-node"
43

54
import 'reflect-metadata';
65
import './polyfills/array';
6+
import {SanitizationService} from '@angular/core/src/security';
77
import {isPresent, Type, print} from '@angular/core/src/facade/lang';
88
import {ReflectiveInjector, reflector, coreLoadAndBootstrap, createPlatform,
99
getPlatform, assertPlatform, ComponentRef, PlatformRef, PLATFORM_DIRECTIVES, PLATFORM_PIPES} from '@angular/core';
1010
import {bind, provide, Provider} from '@angular/core/src/di';
1111

1212
import {RootRenderer, Renderer} from '@angular/core/src/render/api';
1313
import {NativeScriptRootRenderer, NativeScriptRenderer} from './renderer';
14-
import {NativeScriptDomAdapter, NativeScriptElementSchemaRegistry} from './dom_adapter';
14+
import {NativeScriptDomAdapter, NativeScriptElementSchemaRegistry, NativeScriptSanitizationService} from './dom_adapter';
1515
import {ElementSchemaRegistry, XHR, COMPILER_PROVIDERS} from '@angular/compiler';
1616
import {FileSystemXHR} from './xhr';
1717
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
@@ -46,7 +46,7 @@ class ConsoleLogger {
4646
}
4747

4848
export function bootstrap(appComponentType: any,
49-
customProviders: ProviderArray = null): Promise<ComponentRef> {
49+
customProviders: ProviderArray = null): Promise<ComponentRef<any>> {
5050
NativeScriptDomAdapter.makeCurrent();
5151

5252
let platformProviders: ProviderArray = [
@@ -69,6 +69,7 @@ export function bootstrap(appComponentType: any,
6969
provide(RootRenderer, { useClass: NativeScriptRootRenderer }),
7070
NativeScriptRenderer,
7171
provide(Renderer, { useClass: NativeScriptRenderer }),
72+
provide(SanitizationService, { useClass: NativeScriptSanitizationService }),
7273
provide(ElementSchemaRegistry, { useClass: NativeScriptElementSchemaRegistry }),
7374
COMPILER_PROVIDERS,
7475
provide(ElementSchemaRegistry, { useClass: NativeScriptElementSchemaRegistry }),
@@ -90,7 +91,7 @@ export function bootstrap(appComponentType: any,
9091
return coreLoadAndBootstrap(appInjector, appComponentType);
9192
}
9293

93-
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions): Promise<ComponentRef> {
94+
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions): Promise<ComponentRef<any>> {
9495
if (appOptions && appOptions.cssFile) {
9596
application.cssFile = appOptions.cssFile;
9697
}

src/nativescript-angular/dom_adapter.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import {ElementSchemaRegistry} from '@angular/compiler';
2-
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
2+
import {SanitizationService} from '@angular/core/src/security';
3+
import {Parse5DomAdapter} from '@angular/platform-server';
34
import {setRootDomAdapter} from '@angular/platform-browser/src/dom/dom_adapter';
45
import {Type} from '@angular/core/src/facade/lang';
56

7+
export enum SecurityContext {
8+
NONE,
9+
HTML,
10+
STYLE,
11+
SCRIPT,
12+
URL,
13+
RESOURCE_URL,
14+
}
15+
616
export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry {
717
hasProperty(tagName: string, propName: string): boolean {
818
return true;
@@ -11,6 +21,16 @@ export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry {
1121
getMappedPropName(propName: string): string {
1222
return propName;
1323
}
24+
25+
securityContext(tagName: string, propName: string): any {
26+
return SecurityContext.NONE;
27+
}
28+
}
29+
30+
export class NativeScriptSanitizationService extends SanitizationService {
31+
sanitize(context: SecurityContext, value: string): string {
32+
return value;
33+
}
1434
}
1535

1636
export class NativeScriptDomAdapter extends Parse5DomAdapter {

0 commit comments

Comments
 (0)