From 3b1c744e37323bb0820791ee1a8885fedfde6192 Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Mon, 4 Feb 2013 20:17:49 +0000 Subject: QPID-4565: Setting message content turned maps and lists into strings. When setting content for a message, the Ruby code attempted to convert anything that was a symbol to a string. But it was overzealous and converted everything to a string, including map values that were themselves maps or lists. This fix now only converts symbols to strings. It steps down through arrays or lists and only converts its elements that are symbols to strings, leaving anything else as is. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1442329 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/ruby/lib/qpid_messaging/encoding.rb | 29 ++++++++++++++++++++++ .../qpid/ruby/lib/qpid_messaging/message.rb | 16 ++++-------- 2 files changed, 34 insertions(+), 11 deletions(-) (limited to 'cpp') diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb index f04dcea1db..28475f84fd 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb @@ -52,6 +52,35 @@ module Qpid message.content end + # Takes as input any type and converts anything that's a symbol + # into a string. + def self.stringify(value) + # set the default value + result = value + + case value + + when Symbol + result = value.to_s + + when Hash + result = {} + value.each_pair do |key, value| + result[stringify(key)] = stringify(value) + end + + when Array + result = [] + value.each do |element| + result << stringify(element) + end + + end + + return result + + end + end end diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb index d58b10b1e5..b9f54b981c 100644 --- a/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb +++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb @@ -283,14 +283,14 @@ module Qpid # Assigns a value to the named property. # - # *NOTE:* Both the key or the value may be a symbol, but they will - # both be converted to a +String+ for ease of transport. - # # ==== Options # # * name - the property name # * value - the property value - def []=(key, value); @message_impl.setProperty(key.to_s, value.to_s); end + def []=(key, value) + @message_impl.setProperty(key.to_s, + Qpid::Messaging.stringify(value)) + end # Sets the content for the +Message+. # @@ -309,18 +309,12 @@ module Qpid # def content=(content) content_type = nil - @content = content + @content = Qpid::Messaging.stringify(content) case @content when Hash content_type = "amqp/map" - new_content = {} - content.each_pair{|key, value| new_content[key.to_s] = value.to_s} - @content = new_content when Array - new_content = [] content_type = "amqp/list" - content.each {|element| new_content << element.to_s} - @content = new_content end if content_type.nil? @message_impl.setContent @content -- cgit v1.2.1