@@ -317,14 +317,14 @@ fn escape(s string, mode EncodingMode) string {
317317pub struct URL {
318318pub mut :
319319 scheme string
320- opaque string // encoded opaque data
321- user & Userinfo = unsafe { nil } // username and password information
322- host string // host or host:port
323- path string // path (relative paths may omit leading slash)
324- raw_path string // encoded path hint (see escaped_path method)
325- force_query bool // append a query ('?') even if raw_query is empty
326- raw_query string // encoded query values, without '?'
327- fragment string // fragment for references, without '#'
320+ opaque string // encoded opaque data
321+ user ? Userinfo // username and password information
322+ host string // host or host:port
323+ path string // path (relative paths may omit leading slash)
324+ raw_path string // encoded path hint (see escaped_path method)
325+ force_query bool // append a query ('?') even if raw_query is empty
326+ raw_query string // encoded query values, without '?'
327+ fragment string // fragment for references, without '#'
328328}
329329
330330// debug returns a string representation of *ALL* the fields of the given URL
@@ -334,8 +334,8 @@ pub fn (url &URL) debug() string {
334334
335335// user returns a Userinfo containing the provided username
336336// and no password set.
337- pub fn user (username string ) & Userinfo {
338- return & Userinfo{
337+ pub fn user (username string ) Userinfo {
338+ return Userinfo{
339339 username: username
340340 password: ''
341341 password_set: false
@@ -350,8 +350,8 @@ pub fn user(username string) &Userinfo {
350350// ``is NOT RECOMMENDED, because the passing of authentication
351351// information in clear text (such as URI) has proven to be a
352352// security risk in almost every case where it has been used.''
353- fn user_password (username string , password string ) & Userinfo {
354- return & Userinfo{username, password, true }
353+ fn user_password (username string , password string ) Userinfo {
354+ return Userinfo{username, password, true }
355355}
356356
357357// The Userinfo type is an immutable encapsulation of username and
@@ -365,13 +365,13 @@ pub:
365365 password_set bool
366366}
367367
368- fn (u & Userinfo) empty () bool {
369- return isnil (u) || (u .username == '' && u.password == '' )
368+ fn (u Userinfo) empty () bool {
369+ return u .username == '' && u.password == ''
370370}
371371
372372// string returns the encoded userinfo information in the standard form
373373// of 'username[:password]'.
374- fn (u & Userinfo) str () string {
374+ fn (u Userinfo) str () string {
375375 if u.empty () {
376376 return ''
377377 }
@@ -471,7 +471,7 @@ fn parse_url(rawurl string, via_request bool) !URL {
471471 return error (error_msg ('parse_url: empty URL' , rawurl))
472472 }
473473 mut url := URL{
474- user: unsafe { nil }
474+ user: none
475475 }
476476 if rawurl == '*' {
477477 url.path = '*'
@@ -533,7 +533,7 @@ fn parse_url(rawurl string, via_request bool) !URL {
533533}
534534
535535struct ParseAuthorityRes {
536- user & Userinfo
536+ user ? Userinfo
537537 host string
538538}
539539
@@ -697,7 +697,7 @@ fn valid_optional_port(port string) bool {
697697//
698698// In the second form, the following rules apply:
699699// - if u.scheme is empty, scheme: is omitted.
700- // - if u.user is nil , userinfo@ is omitted.
700+ // - if u.user is none , userinfo@ is omitted.
701701// - if u.host is empty, host/ is omitted.
702702// - if u.scheme and u.host are empty and u.user is nil,
703703// the entire scheme://userinfo@host/ is omitted.
@@ -714,12 +714,13 @@ pub fn (u URL) str() string {
714714 if u.opaque != '' {
715715 buf.write_string (u.opaque)
716716 } else {
717- if u.scheme != '' || u.host != '' || ! u.user.empty () {
718- if u.host != '' || u.path != '' || ! u.user.empty () {
717+ user := u.user or { Userinfo{} }
718+ if u.scheme != '' || u.host != '' || ! user.empty () {
719+ if u.host != '' || u.path != '' || ! user.empty () {
719720 buf.write_string ('//' )
720721 }
721- if ! u. user.empty () {
722- buf.write_string (u. user.str ())
722+ if ! user.empty () {
723+ buf.write_string (user.str ())
723724 buf.write_string ('@' )
724725 }
725726 if u.host != '' {
@@ -921,7 +922,8 @@ pub fn (u &URL) resolve_reference(ref &URL) !URL {
921922 if ref.scheme == '' {
922923 url.scheme = u.scheme
923924 }
924- if ref.scheme != '' || ref.host != '' || ! ref.user.empty () {
925+ ref_user := ref.user or { Userinfo{} }
926+ if ref.scheme != '' || ref.host != '' || ! ref_user.empty () {
925927 // The 'absoluteURI' or 'net_path' cases.
926928 // We can ignore the error from set_path since we know we provided a
927929 // validly-escaped path.
0 commit comments