From 40cefc9844100474eba84d33ab77362d69321db9 Mon Sep 17 00:00:00 2001 From: nahi Date: Sat, 2 Sep 2006 03:11:02 +0000 Subject: * lib/soap/generator.rb (SOAP::SOAPGenerator#encode_tag): do not dump XML attribute which value is nil. value "" and nil both were dumped as 'attr="value"'. [ruby-dev:29395] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/soap/generator.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/soap/generator.rb b/lib/soap/generator.rb index f179555e1d..d0c07b058a 100644 --- a/lib/soap/generator.rb +++ b/lib/soap/generator.rb @@ -156,16 +156,22 @@ public end def encode_tag(elename, attrs = nil) - if !attrs or attrs.empty? + if attrs.nil? or attrs.empty? @buf << "\n#{ @indent }<#{ elename }>" - elsif attrs.size == 1 - key, value = attrs.shift - @buf << %Q[\n#{ @indent }<#{ elename } #{ key }="#{ value }">] + return + end + ary = [] + attrs.each do |key, value| + ary << %Q[#{ key }="#{ value }"] unless value.nil? + end + case ary.size + when 0 + @buf << "\n#{ @indent }<#{ elename }>" + when 1 + @buf << %Q[\n#{ @indent }<#{ elename } #{ ary[0] }>] else @buf << "\n#{ @indent }<#{ elename } " << - attrs.collect { |key, value| - %Q[#{ key }="#{ value }"] - }.join("\n#{ @indent }#{ @indentstr * 2 }") << + ary.join("\n#{ @indent }#{ @indentstr * 2 }") << '>' end end -- cgit v1.2.3