Skip to content

Commit 303b7b7

Browse files
committed
Remove normalization and prefer .build.
1 parent f262bdd commit 303b7b7

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/async/redis/endpoint.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def self.remote(host, port = 6379, **options)
3636
}
3737

3838
def self.parse(string, endpoint = nil, **options)
39-
url = URI.parse(string).normalize
39+
url = URI.parse(string)
4040

4141
return self.new(url, endpoint, **options)
4242
end
@@ -55,10 +55,14 @@ def self.for(scheme, host, credentials: nil, port: nil, database: nil, **options
5555
path = "/#{database}"
5656
end
5757

58-
host = host.include?(":") ? "[#{host}]" : host
59-
6058
self.new(
61-
uri_klass.new(scheme, credentials&.join(":"), host, port, nil, path, nil, nil, nil).normalize,
59+
uri_klass.build(
60+
scheme: scheme,
61+
userinfo: credentials&.join(":"),
62+
host: host,
63+
port: port,
64+
path: path,
65+
),
6266
**options
6367
)
6468
end

test/async/redis/endpoint.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@
8181
with ".for" do
8282
it "handles IPv4 addresses correctly" do
8383
endpoint = Async::Redis::Endpoint.for("redis", "127.0.0.1", port: 6380)
84-
expect(endpoint.url.to_s).to be == "redis://127.0.0.1:6380/"
84+
expect(endpoint.url.to_s).to be == "redis://127.0.0.1:6380"
8585
expect(endpoint.url.host).to be == "127.0.0.1"
8686
expect(endpoint.url.hostname).to be == "127.0.0.1"
8787
expect(endpoint.port).to be == 6380
8888
end
8989

9090
it "handles IPv6 addresses correctly" do
9191
endpoint = Async::Redis::Endpoint.for("redis", "::1", port: 6380)
92-
expect(endpoint.url.to_s).to be == "redis://[::1]:6380/"
92+
expect(endpoint.url.to_s).to be == "redis://[::1]:6380"
9393
expect(endpoint.url.host).to be == "[::1]"
9494
expect(endpoint.url.hostname).to be == "::1"
9595
expect(endpoint.port).to be == 6380
@@ -98,15 +98,15 @@
9898
it "handles expanded IPv6 addresses correctly" do
9999
ipv6 = "2600:1f28:372:c404:5c2d:ce68:3620:cc4b"
100100
endpoint = Async::Redis::Endpoint.for("redis", ipv6, port: 6380)
101-
expect(endpoint.url.to_s).to be == "redis://[#{ipv6}]:6380/"
101+
expect(endpoint.url.to_s).to be == "redis://[#{ipv6}]:6380"
102102
expect(endpoint.url.host).to be == "[#{ipv6}]"
103103
expect(endpoint.url.hostname).to be == ipv6
104104
expect(endpoint.port).to be == 6380
105105
end
106106

107107
it "handles credentials correctly" do
108108
endpoint = Async::Redis::Endpoint.for("redis", "localhost", credentials: ["user", "pass"], port: 6380)
109-
expect(endpoint.url.to_s).to be == "redis://user:pass@localhost:6380/"
109+
expect(endpoint.url.to_s).to be == "redis://user:pass@localhost:6380"
110110
expect(endpoint.url.userinfo).to be == "user:pass"
111111
expect(endpoint.credentials).to be == ["user", "pass"]
112112
end
@@ -120,7 +120,7 @@
120120

121121
it "handles secure connections correctly" do
122122
endpoint = Async::Redis::Endpoint.for("rediss", "localhost")
123-
expect(endpoint.url.to_s).to be == "rediss://localhost/"
123+
expect(endpoint.url.to_s).to be == "rediss://localhost"
124124
expect(endpoint).to be(:secure?)
125125
end
126126

0 commit comments

Comments
 (0)