diff options
| author | Darryl L. Pierce <mcpierce@apache.org> | 2013-02-04 20:17:49 +0000 |
|---|---|---|
| committer | Darryl L. Pierce <mcpierce@apache.org> | 2013-02-04 20:17:49 +0000 |
| commit | 1636925b841cbb6e7c756bcbeb6775f235344d8d (patch) | |
| tree | 1bbd6010f349cbf2abd59383542492552d1c5cc7 /qpid/cpp/bindings | |
| parent | a988593274651f43c43f8cfcf467084ecc9ba149 (diff) | |
| download | qpid-python-1636925b841cbb6e7c756bcbeb6775f235344d8d.tar.gz | |
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@1442329 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/bindings')
| -rw-r--r-- | qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb | 29 | ||||
| -rw-r--r-- | qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb | 16 |
2 files changed, 34 insertions, 11 deletions
diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb index f04dcea1db..28475f84fd 100644 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb +++ b/qpid/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/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb index d58b10b1e5..b9f54b981c 100644 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb +++ b/qpid/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 |
