Skip to content

Commit cdd79aa

Browse files
author
Amir Tocker
committed
Support symbols in context
1 parent 367e25d commit cdd79aa

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/cloudinary/utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def self.encode_hash(hash)
681681
# @private
682682
def self.encode_context(hash)
683683
case hash
684-
when Hash then hash.map{|k,v| "#{k}=#{v.gsub(/([=|])/, '\\\\\1')}"}.join("|")
684+
when Hash then hash.map{|k,v| "#{k}=#{v.to_s.gsub(/([=|])/, '\\\\\1')}"}.join("|")
685685
when nil then ""
686686
else hash
687687
end

spec/utils_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,4 +876,20 @@
876876

877877
end
878878
end
879+
880+
describe "context" do
881+
it 'should escape pipe and backslash characters' do
882+
context = {"caption" => "different = caption", "alt2" => "alt|alternative"}
883+
result = Cloudinary::Utils.encode_context(context)
884+
expect(result).to eq("caption=different \\= caption|alt2=alt\\|alternative")
885+
.or eq("alt2=alt\\|alternative|caption=different \\= caption")
886+
887+
end
888+
it 'should support symbols' do
889+
context = {:symbol_key => "string_value", "string_key" => :symbol_value}
890+
result = Cloudinary::Utils.encode_context(context)
891+
expect(result).to eq("string_key=symbol_value|symbol_key=string_value")
892+
.or eq("symbol_key=string_value|string_key=symbol_value")
893+
end
894+
end
879895
end

0 commit comments

Comments
 (0)