Skip to content

Commit

Permalink
fix: handle static ICM content links in CMS content (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrueber authored Dec 4, 2023
1 parent a0ee491 commit eb03fde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/app/core/directives/server-html.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ describe('Server Html Directive', () => {
let element: HTMLElement;

beforeEach(() => {
const appFacade = mock(AppFacade);
when(appFacade.icmBaseUrl).thenReturn('http://example.org');

@Component({
template: ` <div [ishServerHtml]="html"></div> `,
changeDetection: ChangeDetectionStrategy.OnPush,
})
class TestComponent {
html = `<div><a href="product://8182790134362@inSPIRED-inTRONICS">Product</a></div>
<div><a href="http://google.de">Google</a></div>
<div><a href="route://basket">Basket</a></div>`;
<div><a href="route://basket">Basket</a></div>
<div><a href="/INTERSHOP/static/WFS/channel/test.pdf">Relative Pdf link</a></div>`;
}

TestBed.configureTestingModule({
declarations: [ServerHtmlDirective, TestComponent],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: AppFacade, useFactory: () => instance(mock(AppFacade)) },
{ provide: AppFacade, useFactory: () => instance(appFacade) },
],
}).compileComponents();

Expand All @@ -43,6 +47,9 @@ describe('Server Html Directive', () => {
<div><a href="/product/8182790134362">Product</a></div>
<div><a href="http://google.de">Google</a></div>
<div><a href="/basket">Basket</a></div>
<div>
<a href="http://example.org/INTERSHOP/static/WFS/channel/test.pdf">Relative Pdf link</a>
</div>
</div>
`);
});
Expand Down
8 changes: 7 additions & 1 deletion src/app/core/directives/server-html.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ export class ServerHtmlDirective implements AfterContentInit, AfterViewInit, OnC
private patchElements() {
// use setAttribute here to bypass security check
Array.from(this.elementRef.nativeElement.querySelectorAll('[href]')).forEach((element: HTMLElement) => {
this.renderer.setAttribute(element, 'href', LinkParser.parseLink(element.getAttribute('href'), this.baseHref));
const href = element.getAttribute('href');

this.renderer.setAttribute(
element,
'href',
href.startsWith('/INTERSHOP/') ? this.transformMediaObjectSrc(href) : LinkParser.parseLink(href, this.baseHref)
);
});
Array.from(this.elementRef.nativeElement.querySelectorAll('[src]')).forEach((element: HTMLElement) => {
this.renderer.setAttribute(element, 'src', this.transformMediaObjectSrc(element.getAttribute('src')));
Expand Down

0 comments on commit eb03fde

Please sign in to comment.