Skip to content

Commit 80649ea

Browse files
FrozenPandazchuckjaz
authored andcommitted
fix(platform-server): correctly implement get href in parse5 adapter (#15022)
1 parent 778f7d6 commit 80649ea

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/platform-server/src/parse5_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class Parse5DomAdapter extends DomAdapter {
505505
isShadowRoot(node: any): boolean { return this.getShadowRoot(node) == node; }
506506
importIntoDoc(node: any): any { return this.clone(node); }
507507
adoptNode(node: any): any { return node; }
508-
getHref(el: any): string { return el.href; }
508+
getHref(el: any): string { return this.getAttribute(el, 'href'); }
509509
resolveAndSetHref(el: any, baseUrl: string, href: string) {
510510
if (href == null) {
511511
el.href = baseUrl;

packages/platform-server/test/integration_spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {PlatformLocation, isPlatformServer} from '@angular/common';
9+
import {APP_BASE_HREF, PlatformLocation, isPlatformServer} from '@angular/common';
1010
import {ApplicationRef, CompilerFactory, Component, NgModule, NgModuleRef, NgZone, PLATFORM_ID, PlatformRef, destroyPlatform, getPlatform} from '@angular/core';
1111
import {TestBed, async, inject} from '@angular/core/testing';
1212
import {Http, HttpModule, Response, ResponseOptions, XHRBackend} from '@angular/http';
@@ -170,6 +170,19 @@ export function main() {
170170
});
171171
}));
172172

173+
it('should get base href from document', async(() => {
174+
const platform = platformDynamicServer([{
175+
provide: INITIAL_CONFIG,
176+
useValue:
177+
{document: '<html><head><base href="/"></head><body><app></app></body></html>'}
178+
}]);
179+
platform.bootstrapModule(ExampleModule).then((moduleRef) => {
180+
const location = moduleRef.injector.get(PlatformLocation);
181+
expect(location.getBaseHrefFromDOM()).toEqual('/');
182+
platform.destroy();
183+
});
184+
}));
185+
173186
it('adds styles with ng-transition attribute', async(() => {
174187
const platform = platformDynamicServer([{
175188
provide: INITIAL_CONFIG,

0 commit comments

Comments
 (0)