Skip to content

Commit 31adb31

Browse files
UFAL/Fix: preserve namespace in OAI link rewrite on static pages (#1226) (#1227)
1 parent 6ea61f9 commit 31adb31

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/app/static-page/static-page.component.spec.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('StaticPageComponent', () => {
6060

6161
it('should rewrite OAI link with rest.baseUrl', async () => {
6262
const oaiHtml = '<a href="/server/oai/request?verb=ListSets">OAI</a>';
63-
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/rest');
63+
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/server');
6464

6565
await component.ngOnInit();
6666
fixture.detectChanges();
@@ -83,18 +83,31 @@ describe('StaticPageComponent', () => {
8383

8484
it('should avoid double slashes when rest.baseUrl ends with slash', async () => {
8585
const oaiHtml = '<a href="/server/oai/request?verb=ListRecords">OAI</a>';
86-
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/rest/');
86+
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/server/');
8787

8888
await component.ngOnInit();
8989
fixture.detectChanges();
9090

9191
expect(component.htmlContent.value).toContain('https://api.example.org/server/oai/request?verb=ListRecords');
92-
expect(component.htmlContent.value).not.toContain('//server');
92+
expect(component.htmlContent.value).not.toContain('//oai');
93+
});
94+
95+
it('should include namespace in OAI link when rest.baseUrl has namespace prefix', async () => {
96+
const oaiHtml = '<a href="/server/oai/request?verb=ListMetadataFormats">full list</a>';
97+
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/repository/server');
98+
99+
await component.ngOnInit();
100+
fixture.detectChanges();
101+
102+
const rewritten = 'https://api.example.org/repository/server/oai/request?verb=ListMetadataFormats';
103+
expect(component.htmlContent.value).toContain(rewritten);
104+
const anchor = fixture.nativeElement.querySelector('a');
105+
expect(anchor.getAttribute('href')).toBe(rewritten);
93106
});
94107

95108
it('should leave content unchanged when no OAI link is present', async () => {
96109
const otherHtml = '<a href="/server/other">Other</a>';
97-
const { fixture, component } = await setupTest(otherHtml, 'https://api.example.org/rest');
110+
const { fixture, component } = await setupTest(otherHtml, 'https://api.example.org/server');
98111

99112
await component.ngOnInit();
100113
fixture.detectChanges();

src/app/static-page/static-page.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class StaticPageComponent implements OnInit {
3131
let htmlContent = await this.htmlContentService.getHmtlContentByPathAndLocale(this.htmlFileName);
3232
if (isNotEmpty(htmlContent)) {
3333
const restBase = this.appConfig?.rest?.baseUrl;
34-
const oaiUrl = restBase ? new URL('/server/oai', restBase).href : '/server/oai';
34+
const oaiUrl = restBase ? restBase.replace(/\/+$/, '') + '/oai' : '/server/oai';
3535
htmlContent = htmlContent.replace(/href="\/server\/oai/gi, 'href="' + oaiUrl);
3636

3737
this.htmlContent.next(htmlContent);

0 commit comments

Comments
 (0)