From f093501501e8dc4cb762c5143e9ed371e268e617 Mon Sep 17 00:00:00 2001 From: vikerman Date: Tue, 14 Mar 2017 15:40:55 -0700 Subject: [PATCH] fix(platform-server): support svg elements with namespaced attributes (#15101) --- .../platform-server/src/parse5_adapter.ts | 10 ++++++--- .../platform-server/test/integration_spec.ts | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/platform-server/src/parse5_adapter.ts b/packages/platform-server/src/parse5_adapter.ts index 27fb309fbb..2337f97550 100644 --- a/packages/platform-server/src/parse5_adapter.ts +++ b/packages/platform-server/src/parse5_adapter.ts @@ -453,11 +453,15 @@ export class Parse5DomAdapter extends DomAdapter { hasAttribute(element: any, attribute: string): boolean { return element.attribs && element.attribs[attribute] != null; } - hasAttributeNS(element: any, ns: string, attribute: string): boolean { throw 'not implemented'; } + hasAttributeNS(element: any, ns: string, attribute: string): boolean { + return this.hasAttribute(element, attribute); + } getAttribute(element: any, attribute: string): string { return this.hasAttribute(element, attribute) ? element.attribs[attribute] : null; } - getAttributeNS(element: any, ns: string, attribute: string): string { throw 'not implemented'; } + getAttributeNS(element: any, ns: string, attribute: string): string { + return this.getAttribute(element, attribute); + } setAttribute(element: any, attribute: string, value: string) { if (attribute) { element.attribs[attribute] = value; @@ -467,7 +471,7 @@ export class Parse5DomAdapter extends DomAdapter { } } setAttributeNS(element: any, ns: string, attribute: string, value: string) { - throw 'not implemented'; + this.setAttribute(element, attribute, value); } removeAttribute(element: any, attribute: string) { if (attribute) { diff --git a/packages/platform-server/test/integration_spec.ts b/packages/platform-server/test/integration_spec.ts index d74a6d3497..f2da2c45ae 100644 --- a/packages/platform-server/test/integration_spec.ts +++ b/packages/platform-server/test/integration_spec.ts @@ -70,6 +70,18 @@ class MyAsyncServerApp { class AsyncServerModule { } +@Component({selector: 'app', template: ''}) +class SVGComponent { +} + +@NgModule({ + declarations: [SVGComponent], + imports: [BrowserModule.withServerTransition({appId: 'svg-server'}), ServerModule], + bootstrap: [SVGComponent] +}) +class SVGServerModule { +} + @Component({selector: 'app', template: `Works!`, styles: [':host { color: red; }']}) class MyStylesApp { } @@ -322,6 +334,15 @@ export function main() { called = true; }); }))); + + it('works with SVG elements', async(() => { + renderModule(SVGServerModule, {document: doc}).then(output => { + expect(output).toBe( + '' + + ''); + called = true; + }); + })); }); describe('http', () => {