lib/maven/tools/visitor.rb in maven-tools-1.0.0.rc2 vs lib/maven/tools/visitor.rb in maven-tools-1.0.0.rc3

- old
+ new

@@ -20,11 +20,12 @@ def start_raw_tag( name, attr = {} ) @io.print "#{indent}<#{name}" attr.each do |k,v| @io.puts - @io.print "#{indent} #{k.to_s[1..-1]}='#{v}'" + vv = v.gsub( /"/, '&quot;' ) + @io.print "#{indent} #{k.to_s[1..-1]}=\"#{vv}\"" end @io.puts ">" inc end @@ -40,19 +41,23 @@ def end_tag( name ) end_raw_tag( camel_case_lower( name ) ) end def tag( name, value ) - unless value.nil? - name = camel_case_lower( name ) - @io.puts "#{indent}<#{name}>#{value}</#{name}>" + if value != nil + if value.respond_to? :to_xml + @io.puts "#{indent}#{value.to_xml}" + else + name = camel_case_lower( name ) + @io.puts "#{indent}<#{name}>#{escape_value( value )}</#{name}>" + end end end def raw_tag( name, value ) unless value.nil? - @io.puts "#{indent}<#{name}>#{value}</#{name}>" + @io.puts "#{indent}<#{name}>#{escape_value( value )}</#{name}>" end end def camel_case_lower( str ) str = str.to_s @@ -117,25 +122,35 @@ end end def accept_hash( name, hash ) unless hash.empty? - # TODO attributes attr = hash.select do |k, v| [ k, v ] if k.to_s.match( /^@/ ) end start_tag( name, attr ) hash.each do |k, v| case v when Array accept_array( k, v ) + when Hash + accept_hash( k, v ) else - # TODO xml content tag( k, v ) unless k.to_s.match( /^@/ ) end end end_tag( name ) end + end + + def escape_value( value ) + value = value.to_s + value.gsub!( /&/, '&amp;' ) + # undo double quote, somehow xyz.gemspec.rz have encoded values + value.gsub!( /&amp;(amp|lt|gt);/, '&\1;' ) + value.gsub!( /</, '&lt;' ) + value.gsub!( />/, '&gt;' ) + value end def visit( model ) model.attributes.each do |k, v| if k == :properties