Explorar el Código

DialURL ignores opaque url

Fixes #430
LE Manh Cuong hace 6 años
padre
commit
574c33c3df
Se han modificado 2 ficheros con 8 adiciones y 0 borrados
  1. 4 0
      redis/conn.go
  2. 4 0
      redis/conn_test.go

+ 4 - 0
redis/conn.go

@@ -265,6 +265,10 @@ func DialURL(rawurl string, options ...DialOption) (Conn, error) {
 		return nil, fmt.Errorf("invalid redis URL scheme: %s", u.Scheme)
 	}
 
+	if u.Opaque != "" {
+		return nil, fmt.Errorf("invalid redis URL, url is opaque: %s", rawurl)
+	}
+
 	// As per the IANA draft spec, the host defaults to localhost and
 	// the port defaults to 6379.
 	host, port, err := net.SplitHostPort(u.Host)

+ 4 - 0
redis/conn_test.go

@@ -553,6 +553,10 @@ var dialErrors = []struct {
 		"redis://localhost:6379/abc123",
 		"invalid database: abc123",
 	},
+	{
+		"redis:foo//localhost:6379",
+		"invalid redis URL, url is opaque: redis:foo//localhost:6379",
+	},
 }
 
 func TestDialURLErrors(t *testing.T) {