net.urllib: fix parsing url error, when querypath is '//' (fix #20476) (#20504)

This commit is contained in:
shove 2024-01-13 04:51:48 +08:00 committed by GitHub
parent 62872c677f
commit abc9e06ed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -512,7 +512,8 @@ fn parse_url(rawurl string, via_request bool) !URL {
''))
}
}
if ((url.scheme != '' || !via_request) && !rest.starts_with('///')) && rest.starts_with('//') {
if ((url.scheme != '' || !via_request) && !rest.starts_with('///')) && rest.starts_with('//')
&& rest.len > 2 {
authority, r := split(rest[2..], `/`, false)
rest = r
a := parse_authority(authority)!

View File

@ -122,3 +122,9 @@ fn test_parse() {
}
}
}
fn test_parse_slashes() {
assert urllib.parse('/')!.str() == '/'
assert urllib.parse('//')!.str() == '//'
assert urllib.parse('///')!.str() == '///'
}

View File

@ -339,3 +339,16 @@ ${config.content}'
}
return read.bytestr()
}
// for issue 20476
// phenomenon: parsing url error when querypath is `//`
fn test_empty_querypath() {
mut x := http.get('http://${localserver}') or { panic(err) }
assert x.body == 'Welcome to VWeb'
x = http.get('http://${localserver}/') or { panic(err) }
assert x.body == 'Welcome to VWeb'
x = http.get('http://${localserver}//') or { panic(err) }
assert x.body == 'Welcome to VWeb'
x = http.get('http://${localserver}///') or { panic(err) }
assert x.body == 'Welcome to VWeb'
}