-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
url encoded dynamic params not properly handled #8516
Comments
Have similar issue, maybe related: was trying to upgrade to Astro v3 from v2, I'm generating pages with In Astro v3 the issue I have is it works in production build, on start it works in dev instance, it works on reloads, but if I start navigating website with urls I've got
The error appears when I visit same route second time by clicking link to that page. |
i have the same issue with static page after upgrade to Astro 3. Now I have files like category/subcategory.html instead of category/subcategory/index.html |
Similar issue with ssr in middleware mode, urls with special characters and dynamic url blog/{special characters}, |
🤞 |
EDIT: I guess that my problem is entirely different. I might be suffering from this same problem. I left a question in the Discord server... but I'm fearing that my problem is due to a bug and not because of anything wrong I did: https://discord.com/channels/830184174198718474/1210365120832737310 More context on what's happening for my case.
Now, the contents of this file: ---
export const prerender = false
console.log('A')
const { validationKey } = Astro.params
console.log('B')
console.log(validationKey)
---
<div>
<p>We never get to reach this point</p>
<p>{validationKey}</p>
</div> When I visit that route... I don't even get a response (not even a 404, but the browser interprets it as a 404)... BUT, I if I visit
are "printed" on the server side... so it is clear that this code is being executed. Extra: When I run in verbose mode, I have this output:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
I am not really sure there's a fix for that. We do decode params because we run them against our route pattern. The route pattern expects a decoded path (the one you're providing via If we decided to NOT decode params, we could break other users's code. |
|
Can't you just make it optional from config? |
@brokeboiflex We have to fix the correct expectations first. |
@ematipico It's inefficient and dumb af but it got the job done and allowed me to move forward export async function getStaticPaths() {
const products = menuSections.flatMap((category) =>
category.products.map((product) => ({
categoryName: category.categoryName,
productName: product.productName,
productImg: product.productImg,
productPrice: product.productPrice,
productDescription: product.productDescription || '',
variants: product.variants || [],
sizes: product.sizes || [],
}))
)
return products.map((item) => ({
params: {
item:
item.productName
.toLowerCase()
.replaceAll(' ', '-')
.replaceAll('ą', 'a')
.replaceAll('ć', 'c')
.replaceAll('ę', 'e')
.replaceAll('ł', 'l')
.replaceAll('ń', 'n')
.replaceAll('ó', 'o')
.replaceAll('ż', 'z')
.replaceAll('ź', 'z')
},
props: { item },
}))
} |
it is not a problem of decoded/not-decoded, but imho the framework has a little too much magic on this side (and for good reasons, i can see why you guys did that). but spec wise, when the 1st occur, all good (from current behavior), but when somebody really meant the 2nd case, then it won't match the input given at i'm thinking maybe the right move (for this bug and non-english urls) should be not to decode the param for path matching only, mostly because it's a wrong expectation to try matching a freely given string to an url-decoded version of it. but it doesn't mean we have to break code afterwards. i guess that providing url-decoded params value could make sense as the framework could claim making a pass of sanitization for good DX (and it is always possible to reverse it with a call of |
I think the fix would be to change |
We are going to tackle this in Astro v5.0. It's possible there are going to be some breaking changes, but we want to make sure that we have a predictable encoding/decoding strategy. We will follow up with some documentation too. |
@ematipico it's greatly appreciated that this issue is not left in the limbos of the great backlog. thanks a lot for the update. |
Fixed in #12079 |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
i've a url such as
/%5Bpage%5D
coming from a 3rd party place, but handling this valid url ingetStaticPaths
breaks the build.Error log:
What's the expected result?
it should not matter what chars are in a dynamic param as long as it computes to a valid url, and this one seems to be valid according to
new URL('https://example.com/%5Bpage%5D')
.Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-vzlytn?file=src/pages/%5B...path%5D.astro
Participation
The text was updated successfully, but these errors were encountered: