More fixes

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
Josh-Cena 2021-06-17 17:47:03 +08:00
parent 6d3d416f58
commit c7c833fe77
No known key found for this signature in database
GPG key ID: C37145B818BDB68F
16 changed files with 59 additions and 32 deletions

View file

@ -21,6 +21,9 @@ export default function applyTrailingSlash(
function removeTrailingSlash(str: string): string {
return str.endsWith('/') ? str.slice(0, -1) : str;
}
function handleTrailingSlash(str: string, trailing: boolean): string {
return trailing ? addTrailingSlash(str) : removeTrailingSlash(str);
}
// undefined = legacy retrocompatible behavior
if (typeof trailingSlash === 'undefined') {
@ -32,10 +35,6 @@ export default function applyTrailingSlash(
// Never transform '/' to ''
const newPathname =
pathname === '/'
? '/'
: trailingSlash
? addTrailingSlash(pathname)
: removeTrailingSlash(pathname);
pathname === '/' ? '/' : handleTrailingSlash(pathname, trailingSlash);
return path.replace(pathname, newPathname);
}