net.urllib: don't crash on str() if url is missing host (#10313)

This commit is contained in:
Ryan Roden-Corrent 2021-06-02 09:12:27 -04:00 committed by GitHub
parent f6bb4d9a4a
commit a368800b26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -374,7 +374,7 @@ pub:
}
fn (u &Userinfo) empty() bool {
return u.username == '' && u.password == ''
return isnil(u) || (u.username == '' && u.password == '')
}
// string returns the encoded userinfo information in the standard form
@ -737,7 +737,7 @@ pub fn (u URL) str() string {
if u.opaque != '' {
buf.write_string(u.opaque)
} else {
if u.scheme != '' || u.host != '' || (u.user != 0 && !u.user.empty()) {
if u.scheme != '' || u.host != '' || !u.user.empty() {
if u.host != '' || u.path != '' || !u.user.empty() {
buf.write_string('//')
}