Preserve trailing slashes in constructed URLs within buildPathname for improved URL consistency.
This commit is contained in:
+5
-3
@@ -22,8 +22,9 @@ function isSameOriginBaseUrl(baseUrl) {
|
|||||||
|
|
||||||
function buildPathname({ database, kitchenId, path, includeKitchen = true }) {
|
function buildPathname({ database, kitchenId, path, includeKitchen = true }) {
|
||||||
const encodedDatabase = encodeURIComponent(database);
|
const encodedDatabase = encodeURIComponent(database);
|
||||||
const encodedPathSegments = String(path || '')
|
const rawPath = String(path || '').replace(/^\/+/, '');
|
||||||
.replace(/^\/+/, '')
|
const keepTrailingSlash = rawPath.endsWith('/');
|
||||||
|
const encodedPathSegments = rawPath
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((segment) => encodeURIComponent(segment));
|
.map((segment) => encodeURIComponent(segment));
|
||||||
@@ -35,7 +36,8 @@ function buildPathname({ database, kitchenId, path, includeKitchen = true }) {
|
|||||||
|
|
||||||
segments.push(...encodedPathSegments);
|
segments.push(...encodedPathSegments);
|
||||||
|
|
||||||
return `/${segments.join('/')}`;
|
const pathname = `/${segments.join('/')}`;
|
||||||
|
return keepTrailingSlash ? `${pathname}/` : pathname;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildUrl({ baseUrl, database, kitchenId, path, query = {}, includeKitchen = true }) {
|
function buildUrl({ baseUrl, database, kitchenId, path, query = {}, includeKitchen = true }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user