Skip to content

URL Decoding in Dynamic Routes (SSR) #16313

@rktyt

Description

@rktyt

Astro Info

Astro                    v6.1.6
Vite                     v7.3.2
Node                     v22.22.0
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I’m not sure whether this is a bug or a documentation issue.
The values of Astro.url and new URL(Astro.request.url) are different.

This seems to be related to the following change:
https://docs.astro.build/en/guides/upgrade-to/v6/#removed-percent-encoding-in-routes

However, the API reference for Astro.url states:

Astro.url is equivalent to doing new URL(Astro.request.url).

which does not match the current behavior.

Additionally, regarding Astro.params, there is no mention of decoding in the documentation:
https://docs.astro.build/en/reference/api-reference/#params

What's the expected result?

Astro.url and new URL(Astro.request.url) should be identical (i.e., %25 should not be decoded).

Currently, the pathname of Astro.url is partially decoded, which results in an invalid URL and makes it unusable for purposes such as redirects.


The same issue applies to Astro.params.
It should either not be decoded at all, or if decoding is intended, decodeURIComponent should be used instead of decodeURI.

Alternatively, it could be made configurable via astro.config.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-wipyksgd?file=src%2Fpages%2Findex.astro

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)

    Type

    No type
    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