Skip to content

Commit 1d79aed

Browse files
authored
Merge commit from fork
1 parent adecab1 commit 1d79aed

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/utils/url.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ describe('url', () => {
116116
const path = getPath(new Request('http+unix://%2Ftmp%2Fsocket%2Esock/hello/'))
117117
expect(path).toBe('/hello/')
118118
})
119+
120+
it.each([
121+
'http:/example.com/hello', // invalid HTTP URL
122+
'http:///hello', // invalid HTTP URL
123+
'http://a/:/hello', // starts with `/:/`
124+
'x://a/:/hello', // unknown schema
125+
])('getPath - %s', (url) => {
126+
expect(getPath(new Request(url))).toBe(new URL(url).pathname)
127+
})
119128
})
120129

121130
describe('getQueryStrings', () => {

src/utils/url.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ const tryDecodeURI = (str: string) => tryDecode(str, decodeURI)
105105

106106
export const getPath = (request: Request): string => {
107107
const url = request.url
108-
const start = url.indexOf(
109-
'/',
110-
url.charCodeAt(9) === 58
111-
? 13 // http+unix://
112-
: 8 // http:// or https://
113-
)
108+
const start = url.indexOf('/', url.indexOf(':') + 4)
114109
let i = start
115110
for (; i < url.length; i++) {
116111
const charCode = url.charCodeAt(i)

0 commit comments

Comments
 (0)