net.urllib: don't crash on str() if url is missing host (#10313)
parent
f6bb4d9a4a
commit
a368800b26
|
@ -374,7 +374,7 @@ pub:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (u &Userinfo) empty() bool {
|
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
|
// string returns the encoded userinfo information in the standard form
|
||||||
|
@ -737,7 +737,7 @@ pub fn (u URL) str() string {
|
||||||
if u.opaque != '' {
|
if u.opaque != '' {
|
||||||
buf.write_string(u.opaque)
|
buf.write_string(u.opaque)
|
||||||
} else {
|
} 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() {
|
if u.host != '' || u.path != '' || !u.user.empty() {
|
||||||
buf.write_string('//')
|
buf.write_string('//')
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,3 +43,9 @@ fn test_parse_query() ? {
|
||||||
assert q1.data['format'].data == ['"%l: %c %t"']
|
assert q1.data['format'].data == ['"%l: %c %t"']
|
||||||
assert q2.data['format'].data == ['"%l: %c %t"']
|
assert q2.data['format'].data == ['"%l: %c %t"']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_parse_missing_host() ? {
|
||||||
|
// issue #10311
|
||||||
|
url := urllib.parse('http:///') ?
|
||||||
|
assert url.str() == 'http://///'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue