`urlParsed` removes trailing slash
Description
When the urlOriginal is /en/index.pageContext.json?asd=asd and in the address bar is displayed /en/?asd=asd the urlPathname is /en. When the urlOriginal is /en/?asd=asd the urlPathname is /en/.
This behavior is not influenced by disableUrlNormalization: true.
In my opinion the urlPathname should be /en/ when the urlOriginal is /en/index.pageContext.json?asd=asd.
I would be happy to create a PR for this. Probably this lines need to be changed:
https://github.com/vikejs/vike/blob/6dedbfbda96357dcb1fbc21b6643d099948993b4/vike/node/runtime/renderPage/handlePageContextRequestUrl.ts#L25-L36
Are there unit tests for this? Where would you add a unit test?
I agree and PR welcome :+1:
I also agree that'd be good to add some Vitest test for it and create a file vike/vike/node/runtime/renderPage/removePageContextUrlSuffix.spec.ts. Let's export removePageContextUrlSuffix() and after the PR is merged I'll move removePageContextUrlSuffix() in its own file. (Let's move it to its own file later so it's easier for me to read the diffs you made to removePageContextUrlSuffix.)
Inside removePageContextUrlSuffix() we cannot know if it was originally /en/?asd=asd or /en?asd=asd. Should we read Vikes option trailingSlash and act according to that? If so, should trailingSlash be a param in removePageContextUrlSuffix() or for parseUrl()?
Yes, that's an issue: there is no way to know whether /en/index.pageContext.json is for a /en/ or /en URL. I'm thinking a trick could be to use /en//index.pageContext.json if the URL is /en/?
Inside
removePageContextUrlSuffix()we cannot know if it was originally/en/?asd=asdor/en?asd=asd. Should we read Vikes optiontrailingSlashand act according to that? If so, shouldtrailingSlashbe a param inremovePageContextUrlSuffix()or forparseUrl()?
That would be a brittle solution as it would fail for /en URLs then.
Ah, actually more natural: /en/index.pageContext.json/. Much clearer I think.
Where would the trailing slash /en/index.pageContext.json/ be added?
See vike/shared/getPageContextRequestUrl.ts
On Thu, May 2, 2024 at 10:45 AM Robin @.***> wrote:
Where would the trailing slash /en/index.pageContext.json/ being added?
— Reply to this email directly, view it on GitHub https://github.com/vikejs/vike/issues/1629#issuecomment-2089921213, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHVQRRO7N33WP4LLZXSEWDZAH4MHAVCNFSM6AAAAABHDBD3OOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBZHEZDCMRRGM . You are receiving this because you commented.Message ID: @.***>
Closing as it doesn't seem fixable, see https://github.com/vikejs/vike/pull/1632#issuecomment-2104462175.
@openscript Let me know whether this is a blocker for you. Otherwise I'll move on and focus on other priorities.
Thank you @brillout. Even though a nice way to handle this, I'm happy that we collaborated.
It's not a blocker as I can handle it case by case in my implementation.