Skip to content

getRelativeLocaleUrl can return URLs with trailing slash even when trailingSlash is set to "never" #14140

Description

@claus

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

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)feat: i18nRelated to internalization (scope)

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions