From aa16ccda794260dcac4dba3f4ba7f4641f5160de Mon Sep 17 00:00:00 2001 From: Diego Barahona Date: Tue, 28 Mar 2017 14:33:07 -0600 Subject: [PATCH] fix(core): check for undefined on normalizeDebugBindingValue (#15503) DebugServices is parsing false atributes values incorrectly. Parse5 expects a string value for attributes, but currently boolean is being sent. Closes #15494 --- packages/core/src/view/services.ts | 2 +- .../platform-server/test/integration_spec.ts | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/core/src/view/services.ts b/packages/core/src/view/services.ts index 2e191587fc..b9f7ce6c5a 100644 --- a/packages/core/src/view/services.ts +++ b/packages/core/src/view/services.ts @@ -275,7 +275,7 @@ function camelCaseToDashCase(input: string): string { function normalizeDebugBindingValue(value: any): string { try { // Limit the size of the value as otherwise the DOM just gets polluted. - return value ? value.toString().slice(0, 30) : value; + return value != null ? value.toString().slice(0, 30) : value; } catch (e) { return '[ERROR] Exception while trying to serialize the value'; } diff --git a/packages/platform-server/test/integration_spec.ts b/packages/platform-server/test/integration_spec.ts index 1bf08703b4..deb3964aa1 100644 --- a/packages/platform-server/test/integration_spec.ts +++ b/packages/platform-server/test/integration_spec.ts @@ -8,7 +8,7 @@ import {animate, style, transition, trigger} from '@angular/animations'; import {APP_BASE_HREF, PlatformLocation, isPlatformServer} from '@angular/common'; -import {ApplicationRef, CompilerFactory, Component, HostListener, NgModule, NgModuleRef, NgZone, PLATFORM_ID, PlatformRef, ViewEncapsulation, destroyPlatform, getPlatform} from '@angular/core'; +import {ApplicationRef, CompilerFactory, Component, HostListener, Input, NgModule, NgModuleRef, NgZone, PLATFORM_ID, PlatformRef, ViewEncapsulation, destroyPlatform, getPlatform} from '@angular/core'; import {TestBed, async, inject} from '@angular/core/testing'; import {Http, HttpModule, Response, ResponseOptions, XHRBackend} from '@angular/http'; import {MockBackend, MockConnection} from '@angular/http/testing'; @@ -166,6 +166,23 @@ class NativeEncapsulationApp { class NativeExampleModule { } +@Component({selector: 'my-child', template: 'Works!'}) +class MyChildComponent { + @Input() public attr: boolean; +} + +@Component({selector: 'app', template: ''}) +class MyHostComponent { +} + +@NgModule({ + declarations: [MyHostComponent, MyChildComponent], + bootstrap: [MyHostComponent], + imports: [ServerModule, BrowserModule.withServerTransition({appId: 'false-attributes'})] +}) +class FalseAttributesModule { +} + export function main() { if (getDOM().supportsDOMEvents()) return; // NODE only @@ -406,6 +423,15 @@ export function main() { called = true; }); })); + + it('should handle false values on attributes', async(() => { + renderModule(FalseAttributesModule, {document: doc}).then((output) => { + expect(output).toBe( + '' + + 'Works!'); + called = true; + }); + })); }); describe('http', () => {