Preserve trailing slashes in constructed URLs within buildPathname for improved URL consistency.

This commit is contained in:
2026-04-06 16:35:25 +02:00
parent d56da613dd
commit 1521602743
+5 -3
View File
@@ -22,8 +22,9 @@ function isSameOriginBaseUrl(baseUrl) {
function buildPathname({ database, kitchenId, path, includeKitchen = true }) {
const encodedDatabase = encodeURIComponent(database);
const encodedPathSegments = String(path || '')
.replace(/^\/+/, '')
const rawPath = String(path || '').replace(/^\/+/, '');
const keepTrailingSlash = rawPath.endsWith('/');
const encodedPathSegments = rawPath
.split('/')
.filter(Boolean)
.map((segment) => encodeURIComponent(segment));
@@ -35,7 +36,8 @@ function buildPathname({ database, kitchenId, path, includeKitchen = true }) {
segments.push(...encodedPathSegments);
return `/${segments.join('/')}`;
const pathname = `/${segments.join('/')}`;
return keepTrailingSlash ? `${pathname}/` : pathname;
}
function buildUrl({ baseUrl, database, kitchenId, path, query = {}, includeKitchen = true }) {