Skip to content

Commit

Permalink
Fix detecting json unsafe item within job arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and mperham committed Feb 14, 2023
1 parent a552633 commit cbfa0f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/sidekiq/job_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ def json_unsafe_item(item)
when String, Integer, Float, TrueClass, FalseClass, NilClass
nil
when Array
item.find { |e| !json_unsafe_item(e).nil? }
item.each do |e|
unsafe_item = json_unsafe_item(e)
return unsafe_item unless unsafe_item.nil?
end
nil
when Hash
item.each do |k, v|
return k unless String === k
return v unless json_unsafe_item(v).nil?

unsafe_item = json_unsafe_item(v)
return unsafe_item unless unsafe_item.nil?
end
nil
else
item
end
Expand Down
3 changes: 2 additions & 1 deletion test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,15 @@ def call(worker_klass, msg, q, r)
end

it "raises an error when using a Hash with symbols and string as keys as an argument" do
assert_raises ArgumentError do
error = assert_raises ArgumentError do
InterestingJob.perform_async(
{
:some => "hash",
"with" => "different_keys"
}
)
end
assert_match(/but :some is a Symbol/, error.message)
end

it "raises an error when using a Struct as an argument" do
Expand Down

0 comments on commit cbfa0f6

Please sign in to comment.