Skip to content

Commit

Permalink
skip decoding for href
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jul 19, 2024
1 parent bf0a6be commit 373ceed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions vike/utils/parseUrl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/user/@rom",
"href": "/user/%40rom",
"origin": null,
"pathname": "/user/@rom",
"pathnameOriginal": "/user/%40rom",
Expand Down Expand Up @@ -577,7 +577,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/user/%rom",
"href": "/user/%25rom",
"origin": null,
"pathname": "/user/%rom",
"pathnameOriginal": "/user/%25rom",
Expand Down Expand Up @@ -629,7 +629,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/product/ö",
"href": "/product/%C3%B6",
"origin": null,
"pathname": "/product/ö",
"pathnameOriginal": "/product/%C3%B6",
Expand Down Expand Up @@ -664,7 +664,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/ab",
"href": "/ab ",
"origin": null,
"pathname": "/ab",
"pathnameOriginal": "/ab ",
Expand All @@ -682,7 +682,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/ab ",
"href": "/ab%20",
"origin": null,
"pathname": "/ab ",
"pathnameOriginal": "/ab%20",
Expand Down Expand Up @@ -714,7 +714,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/a b",
"href": "/a%20b",
"origin": null,
"pathname": "/a b",
"pathnameOriginal": "/a%20b",
Expand All @@ -733,7 +733,7 @@ describe('parseUrl', () => {
"hash": "",
"hashOriginal": null,
"host": null,
"href": "/b?c",
"href": "/b%3Fc",
"origin": null,
"pathname": "/b?c",
"pathnameOriginal": "/a%23/b%3Fc",
Expand Down Expand Up @@ -923,7 +923,7 @@ describe('parseUrl', () => {
"hash": "âge",
"hashOriginal": "#%C3%A2ge",
"host": "example.com",
"href": "https://example.com/hello/sébastien?fruit=%C3%A2pple&fruit=orânge#%C3%A2ge",
"href": "https://example.com/hello/s%C3%A9bastien?fruit=%C3%A2pple&fruit=orânge#%C3%A2ge",
"origin": "https://example.com",
"pathname": "/hello/sébastien",
"pathnameOriginal": "/some-base-url/hello/s%C3%A9bastien",
Expand Down
6 changes: 4 additions & 2 deletions vike/utils/parseUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@ function parseUrl(url: string, baseServer: string): UrlPrivate {
})

// Origin + pathname
const { protocol, origin, pathnameAbsoluteWithBase } = getPathnameWithBase(urlWithoutHashNorSearch, baseServer)
let { protocol, origin, pathnameAbsoluteWithBase } = getPathnameWithBase(urlWithoutHashNorSearch, baseServer)
const pathnameOriginal = urlWithoutHashNorSearch.slice((origin || '').length)
assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal)

// Base URL
let { pathname, hasBaseServer } = removeBaseServer(pathnameAbsoluteWithBase, baseServer)
pathname = decodePathname(pathname)

// More props
const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal)
const host = !origin ? null : origin.slice(protocol!.length)

// decode after setting href
pathname = decodePathname(pathname)

assert(pathname.startsWith('/'))
return {
href,
Expand Down

0 comments on commit 373ceed

Please sign in to comment.