From b4d180773faf29a8579552d83d4d737e713837b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Lagos?= Date: Thu, 25 Sep 2025 22:14:02 -0300 Subject: [PATCH 1/2] Fix 4734: normalize contextPath handling in bitstream download route --- src/app/app-routing-paths.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/app/app-routing-paths.ts b/src/app/app-routing-paths.ts index 7b2c2d81ce0..1385079467c 100644 --- a/src/app/app-routing-paths.ts +++ b/src/app/app-routing-paths.ts @@ -1,3 +1,4 @@ +import { environment } from 'src/environments/environment'; import { getCollectionPageRoute } from './collection-page/collection-page-routing-paths'; import { getCommunityPageRoute } from './community-page/community-page-routing-paths'; import { Collection } from './core/shared/collection.model'; @@ -22,8 +23,31 @@ export function getBitstreamModuleRoute() { return `/${BITSTREAM_MODULE_PATH}`; } +/** + * Normalizes the application's contextPath: + * - Returns "" if it is "/" or empty. + * - Ensures it starts with "/" if missing. + * - Removes trailing "/" if present. + */ +export function normalizeContextPath(contextPath?: string): string { + if (!contextPath || contextPath === "/") { + return ""; + } + + let path = contextPath.trim(); + + if (!path.startsWith("/")) { + path = "/" + path; + } + if (path.endsWith("/")) { + path = path.slice(0, -1); + } + return path; +} + export function getBitstreamDownloadRoute(bitstream): string { - return new URLCombiner(getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(); + const contextPath = normalizeContextPath(environment.ui.nameSpace); + return new URLCombiner(contextPath+getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(); } export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: string, queryParams: any } { const url = new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString(); From e827aacd9be18d968dcc1b03f40912558f41e93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Lagos?= Date: Thu, 25 Sep 2025 23:31:05 -0300 Subject: [PATCH 2/2] Fix ESLint issues in app-routing-paths.ts --- src/app/app-routing-paths.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/app-routing-paths.ts b/src/app/app-routing-paths.ts index 1385079467c..dd23d3cd636 100644 --- a/src/app/app-routing-paths.ts +++ b/src/app/app-routing-paths.ts @@ -1,4 +1,5 @@ import { environment } from 'src/environments/environment'; + import { getCollectionPageRoute } from './collection-page/collection-page-routing-paths'; import { getCommunityPageRoute } from './community-page/community-page-routing-paths'; import { Collection } from './core/shared/collection.model'; @@ -30,16 +31,16 @@ export function getBitstreamModuleRoute() { * - Removes trailing "/" if present. */ export function normalizeContextPath(contextPath?: string): string { - if (!contextPath || contextPath === "/") { - return ""; + if (!contextPath || contextPath === '/') { + return ''; } let path = contextPath.trim(); - if (!path.startsWith("/")) { - path = "/" + path; + if (!path.startsWith('/')) { + path = '/' + path; } - if (path.endsWith("/")) { + if (path.endsWith('/')) { path = path.slice(0, -1); } return path; @@ -47,7 +48,7 @@ export function normalizeContextPath(contextPath?: string): string { export function getBitstreamDownloadRoute(bitstream): string { const contextPath = normalizeContextPath(environment.ui.nameSpace); - return new URLCombiner(contextPath+getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(); + return new URLCombiner(contextPath + getBitstreamModuleRoute(), bitstream.uuid, 'download').toString(); } export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: string, queryParams: any } { const url = new URLCombiner(getItemModuleRoute(), item.uuid, 'request-a-copy').toString();