Skip to content

Commit 1ffdaa9

Browse files
committed
Default to localhost when no host is found, as per IANA spec.
1 parent 2899813 commit 1ffdaa9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/redis/client.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,8 @@ def _parse_options(options)
392392
if uri.scheme == "unix"
393393
defaults[:path] = uri.path
394394
elsif uri.scheme == "redis"
395-
# Require the URL to have at least a host
396-
raise ArgumentError, "invalid url: #{uri}" unless uri.host
397-
398395
defaults[:scheme] = uri.scheme
399-
defaults[:host] = uri.host
396+
defaults[:host] = uri.host if uri.host
400397
defaults[:port] = uri.port if uri.port
401398
defaults[:password] = CGI.unescape(uri.password) if uri.password
402399
defaults[:db] = uri.path[1..-1].to_i if uri.path

test/url_param_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,10 @@ def test_uses_redis_url_over_default_if_available
129129

130130
ENV.delete("REDIS_URL")
131131
end
132+
133+
def test_defaults_to_localhost
134+
redis = Redis.new(:url => "redis:///")
135+
136+
assert_equal "127.0.0.1", redis.client.host
137+
end
132138
end

0 commit comments

Comments
 (0)