Skip to content

Commit 9ea5a1f

Browse files
authored
Merge pull request #173 from stanhu/sh-freeze-prelude
Ensure all elements of connection prelude are frozen
2 parents 670ac22 + 66c408b commit 9ea5a1f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/redis_client/config.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ def build_connection_prelude
151151
if @db && @db != 0
152152
prelude << ["SELECT", @db.to_s]
153153
end
154+
155+
# Deep freeze all the strings and commands
156+
prelude.map! do |commands|
157+
commands = commands.map { |str| str.frozen? ? str : str.dup.freeze }
158+
commands.freeze
159+
end
154160
prelude.freeze
155161
end
156162
end

test/redis_client/config_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ def test_user_password_uri
7474
refute_predicate config, :ssl?
7575
end
7676

77+
def test_frozen_prelude
78+
config = Config.new(url: "redis://username:[email protected]")
79+
prelude = config.connection_prelude
80+
assert_equal true, prelude.frozen?
81+
assert_equal true, (prelude.all? { |commands| commands.frozen? })
82+
83+
prelude.each do |commands|
84+
assert_equal true, (commands.all? { |arg| arg.frozen? })
85+
end
86+
end
87+
7788
def test_simple_password_uri
7889
config = Config.new(url: "redis://[email protected]")
7990
assert_equal "example.com", config.host

0 commit comments

Comments
 (0)