Skip to content

Commit

Permalink
net.urllib: fix parsing url error, when querypath is '//' (fix #20476) (
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Jan 12, 2024
1 parent 62872c6 commit abc9e06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/net/urllib/urllib.v
Expand Up @@ -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)!
Expand Down
6 changes: 6 additions & 0 deletions vlib/net/urllib/urllib_test.v
Expand Up @@ -122,3 +122,9 @@ fn test_parse() {
}
}
}

fn test_parse_slashes() {
assert urllib.parse('/')!.str() == '/'
assert urllib.parse('//')!.str() == '//'
assert urllib.parse('///')!.str() == '///'
}
13 changes: 13 additions & 0 deletions vlib/vweb/tests/vweb_test.v
Expand Up @@ -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'
}

0 comments on commit abc9e06

Please sign in to comment.