diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index b0a6b888ad..ddeb3472a7 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -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('//') } diff --git a/vlib/net/urllib/urllib_test.v b/vlib/net/urllib/urllib_test.v index 2d354efda7..0870c81bbd 100644 --- a/vlib/net/urllib/urllib_test.v +++ b/vlib/net/urllib/urllib_test.v @@ -43,3 +43,9 @@ fn test_parse_query() ? { assert q1.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://///' +}