@@ -8360,6 +8360,80 @@ func TestHttpUrl(t *testing.T) {
83608360 PanicMatches (t , func () { _ = validate .Var (i , "http_url" ) }, "Bad field type int" )
83618361}
83628362
8363+ func TestHttpsUrl (t * testing.T ) {
8364+ tests := []struct {
8365+ param string
8366+ expected bool
8367+ }{
8368+ {"https://foo.bar#com" , true },
8369+ {"https://foobar.com" , true },
8370+ {"HTTPS://foobar.com" , true },
8371+ {"http://foobar.com" , false },
8372+ {"foobar.com" , false },
8373+ {"https://foobar.coffee/" , true },
8374+ {"https://foobar.中文网/" , true },
8375+ {"https://foobar.org/" , true },
8376+ {"https://foobar.org:8080/" , true },
8377+ {"ftp://foobar.ru/" , false },
8378+ {"file:///etc/passwd" , false },
8379+ {"file://C:/windows/win.ini" , false },
8380+ {
"https://user:[email protected] /" ,
true },
8381+ {"https://127.0.0.1/" , true },
8382+ {"https://duckduckgo.com/?q=%2F" , true },
8383+ {"https://localhost:3000/" , true },
8384+ {"https://foobar.com/?foo=bar#baz=qux" , true },
8385+ {"https://foobar.com?foo=bar" , true },
8386+ {"https://www.xn--froschgrn-x9a.net/" , true },
8387+ {"" , false },
8388+ {"a://b" , false },
8389+ {"xyz://foobar.com" , false },
8390+ {"invalid." , false },
8391+ {".com" , false },
8392+ {"rtmp://foobar.com" , false },
8393+ {"https://www.foo_bar.com/" , true },
8394+ {"https://localhost:3000/" , true },
8395+ {"https://foobar.com/#baz" , true },
8396+ {"https://foobar.com#baz=qux" , true },
8397+ {"https://foobar.com/t$-_.+!*\\ '()," , true },
8398+ {"https://www.foobar.com/~foobar" , true },
8399+ {"https://www.-foobar.com/" , true },
8400+ {"https://www.foo---bar.com/" , true },
8401+ {
"mailto:[email protected] " ,
false },
8402+ {"irc://irc.server.org/channel" , false },
8403+ {"irc://#channel@network" , false },
8404+ {"/abs/test/dir" , false },
8405+ {"./rel/test/dir" , false },
8406+ {"https:" , false },
8407+ {"https://" , false },
8408+ {"https://#invalid" , false },
8409+ {"http://1.1.1.1" , false },
8410+ }
8411+
8412+ validate := New ()
8413+
8414+ for i , test := range tests {
8415+ errs := validate .Var (test .param , "https_url" )
8416+
8417+ if test .expected {
8418+ if ! IsEqual (errs , nil ) {
8419+ t .Fatalf ("Index: %d HTTPS URL failed Error: %s" , i , errs )
8420+ }
8421+ } else {
8422+ if IsEqual (errs , nil ) {
8423+ t .Fatalf ("Index: %d HTTPS URL failed Error: %s" , i , errs )
8424+ } else {
8425+ val := getError (errs , "" , "" )
8426+ if val .Tag () != "https_url" {
8427+ t .Fatalf ("Index: %d HTTPS URL failed Error: %s" , i , errs )
8428+ }
8429+ }
8430+ }
8431+ }
8432+
8433+ i := 1
8434+ PanicMatches (t , func () { _ = validate .Var (i , "https_url" ) }, "Bad field type int" )
8435+ }
8436+
83638437func TestUri (t * testing.T ) {
83648438 tests := []struct {
83658439 param string
0 commit comments