Astro Info
Astro v5.11.2
Node v22.13.1
System macOS (arm64)
Package Manager npm
Output server
Adapter @astrojs/vercel
Integrations none
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
getRelativeLocaleUrl can return URLs with trailing slash even when trailingSlash is set to "never":
getRelativeLocaleUrl('en-GB', '/'); will return /en-gb/
It boils down to a bug in joinPaths, which is called by I18nInternals.getLocaleRelativeUrl, which is called by getRelativeLocaleUrl. joinPaths takes a list of paths and calls removeLeadingForwardSlash on the last one. If that last path is '/', removeLeadingForwardSlash returns an empty string ''. joinPaths then joins all paths with '/', and because the last path is an empty string, the result will have a trailing slash.
What's the expected result?
getRelativeLocaleUrl('en-GB', '/'); should return /en-gb
joinPaths needs to filter(path => path !== '') before join('/').
Also i haven't found any unit tests for these functions, might be a good idea to have some.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-nkcfserk
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
getRelativeLocaleUrl can return URLs with trailing slash even when trailingSlash is set to "never":
getRelativeLocaleUrl('en-GB', '/');will return/en-gb/It boils down to a bug in
joinPaths, which is called byI18nInternals.getLocaleRelativeUrl, which is called bygetRelativeLocaleUrl.joinPathstakes a list of paths and callsremoveLeadingForwardSlashon the last one. If that last path is'/',removeLeadingForwardSlashreturns an empty string''.joinPathsthen joins all paths with'/', and because the last path is an empty string, the result will have a trailing slash.What's the expected result?
getRelativeLocaleUrl('en-GB', '/');should return/en-gbjoinPathsneeds tofilter(path => path !== '')beforejoin('/').Also i haven't found any unit tests for these functions, might be a good idea to have some.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-nkcfserk
Participation