Skip to content

Commit 3b43bb7

Browse files
committedAug 18, 2023
fix: preserve URL origin upon URL path normalization redirection
1 parent b6c20a3 commit 3b43bb7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
 

‎vite-plugin-ssr/utils/parseUrl-extras.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ describe('normalizeUrlPathname()', () => {
1010
expect(normalizeUrlPathname('/')).toBe(null)
1111
expect(normalizeUrlPathname('//')).toBe('/')
1212
expect(normalizeUrlPathname('/////')).toBe('/')
13-
expect(normalizeUrlPathname('https://example.org/p/')).toBe('/p')
13+
expect(normalizeUrlPathname('https://example.org/p/')).toBe('https://example.org/p')
1414
expect(normalizeUrlPathname('/p/?foo=bar#bla')).toBe('/p?foo=bar#bla')
1515
expect(normalizeUrlPathname('////?foo=bar#bla')).toBe('/?foo=bar#bla')
16-
expect(normalizeUrlPathname('https://example.org/some-url/?foo=bar#bla')).toBe('/some-url?foo=bar#bla')
16+
expect(normalizeUrlPathname('https://example.org/some-url/?foo=bar#bla')).toBe('https://example.org/some-url?foo=bar#bla')
1717
})
1818
})

‎vite-plugin-ssr/utils/parseUrl-extras.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ function normalizeUrlPathname(urlOriginal: string): string | null {
5757
const pathnameNormalized = '/' + pathnameOriginal.split('/').filter(Boolean).join('/')
5858
if (pathnameOriginal === pathnameNormalized) return null
5959
assertUrlComponents(urlOriginal, urlParsed.origin, pathnameOriginal, urlParsed.searchOriginal, urlParsed.hashOriginal)
60-
const urlNormalized = createUrl('', pathnameNormalized, urlParsed.searchOriginal, urlParsed.hashOriginal)
60+
const urlNormalized = createUrl(urlParsed.origin, pathnameNormalized, urlParsed.searchOriginal, urlParsed.hashOriginal)
6161
return urlNormalized
6262
}

0 commit comments

Comments
 (0)
Please sign in to comment.