@@ -81,22 +81,33 @@ func ParseURI(s string) (fyne.URI, error) {
81
81
return nil , err
82
82
}
83
83
84
- authority := ""
84
+ authority := l .Authority ()
85
+ authBuilder := strings.Builder {}
86
+ authBuilder .Grow (len (authority .UserInfo ()) + len (authority .Host ()) + len (authority .Port ()) + len ("@[]:" ))
85
87
86
- if userInfo := l .Authority ().UserInfo (); len (userInfo ) > 0 {
87
- authority += userInfo + "@"
88
+ if userInfo := authority .UserInfo (); userInfo != "" {
89
+ authBuilder .WriteString (userInfo )
90
+ authBuilder .WriteByte ('@' )
88
91
}
89
92
90
- authority += l .Authority ().Host ()
93
+ // Per RFC 3986, section 3.2.2, IPv6 addresses must be enclosed in square brackets.
94
+ if host := authority .Host (); strings .Contains (host , ":" ) {
95
+ authBuilder .WriteByte ('[' )
96
+ authBuilder .WriteString (host )
97
+ authBuilder .WriteByte (']' )
98
+ } else {
99
+ authBuilder .WriteString (host )
100
+ }
91
101
92
- if port := l .Authority ().Port (); len (port ) > 0 {
93
- authority += ":" + port
102
+ if port := authority .Port (); port != "" {
103
+ authBuilder .WriteByte (':' )
104
+ authBuilder .WriteString (port )
94
105
}
95
106
96
107
return & uri {
97
108
scheme : scheme ,
98
- authority : authority ,
99
- path : l . Authority () .Path (),
109
+ authority : authBuilder . String () ,
110
+ path : authority .Path (),
100
111
query : l .Query ().Encode (),
101
112
fragment : l .Fragment (),
102
113
}, nil
0 commit comments