@@ -104,6 +104,24 @@ func TestDomainValidator_SafeHostname(t *testing.T) {
104104 assert .ErrorContains (t , e , "input url is missing scheme" )
105105 },
106106 },
107+ {
108+ description : "With port enabled but without scheme and url with https should work" ,
109+ options : DomainValidatorOptions {WithPort : true },
110+ input : "https://example.com" ,
111+ expected : "example.com" ,
112+ },
113+ {
114+ description : "With port enabled but without scheme and url with http should work" ,
115+ options : DomainValidatorOptions {WithPort : true },
116+ input : "http://example.com" ,
117+ expected : "example.com" ,
118+ },
119+ {
120+ description : "With port enabled but without scheme and url with port should work" ,
121+ options : DomainValidatorOptions {WithPort : true },
122+ input : "example.com:8080" ,
123+ expected : "example.com" ,
124+ },
107125 }
108126
109127 for _ , test := range tests {
@@ -194,7 +212,7 @@ func TestDomainValidator_Validate(t *testing.T) {
194212 expected : "ssh://example.com:22" ,
195213 actual : "ssh://example.com" ,
196214 errorFunc : func (t * testing.T , e error ) {
197- assert .ErrorContains (t , e , "failed to get effective port for url" )
215+ assert .ErrorContains (t , e , "port validation is enabled but port is missing in input url and schemes are not enabled " )
198216 },
199217 },
200218 {
@@ -203,9 +221,21 @@ func TestDomainValidator_Validate(t *testing.T) {
203221 expected : "ssh://example.com" ,
204222 actual : "ssh://example.com:22" ,
205223 errorFunc : func (t * testing.T , e error ) {
206- assert .ErrorContains (t , e , "failed to get effective port for url" )
224+ assert .ErrorContains (t , e , "port validation is enabled but port is missing in input url and schemes are not enabled " )
207225 },
208226 },
227+ {
228+ description : "Port enabled but no scheme and https scheme should pass" ,
229+ options : DomainValidatorOptions {WithPort : true },
230+ expected : "https://example.com" ,
231+ actual : "https://example.com" ,
232+ },
233+ {
234+ description : "Port enabled but no scheme and http scheme should pass" ,
235+ options : DomainValidatorOptions {WithPort : true },
236+ expected : "http://example.com" ,
237+ actual : "http://example.com" ,
238+ },
209239 {
210240 description : "Port validation with port and no scheme should fail with different port" ,
211241 options : DomainValidatorOptions {WithPort : true },
0 commit comments