diff --git a/connection_test.go b/connection_test.go
index <HASH>..<HASH> 100644
--- a/connection_test.go
+++ b/connection_test.go
@@ -9,6 +9,7 @@ package amqp
 
 import (
 	"net"
+	"net/url"
 	"sync"
 	"testing"
 )
@@ -75,3 +76,14 @@ func TestConcurrentClose(t *testing.T) {
 	}
 	wg.Wait()
 }
+
+func TestConnectionWithInvalidURIFails(t *testing.T) {
+	_, err := DialConfig(":,%not-a-valid-URI((", Config{})
+	if err == nil {
+		t.Fatalf("connection with invalid URI is expected to fail")
+	}
+
+	if _, urlerr := err.(*url.Error); !urlerr {
+		t.Fatalf("expected a url.Error, got %+v", err)
+	}
+}
\ No newline at end of file
diff --git a/uri.go b/uri.go
index <HASH>..<HASH> 100644
--- a/uri.go
+++ b/uri.go
@@ -54,6 +54,11 @@ type URI struct {
 func ParseURI(uri string) (URI, error) {
 	builder := defaultURI
 
+	_, err := url.ParseRequestURI(uri)
+	if err != nil {
+		return builder, err
+	}
+
 	u, err := url.Parse(uri)
 	if err != nil {
 		return builder, err
Validate URI before attempting to use it