File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
879895end
You can’t perform that action at this time.
0 commit comments