Ticket #111 (closed defect: duplicate)

Opened 13 months ago

Last modified 11 months ago

Entities in attributes aren't replaced correctly when parsing a string

Reported by: gamecreature Owned by: ser
Priority: normal Milestone: 3.1.8
Component: DOM Version: 3.1.6
Severity: normal Keywords:
Cc: Ruby version: Other
Operating system: Other

Description

Entities in an attribute aren't converted correctly when creating a new document:

#
# Create the object
#
xml = REXML::Document.new("<root />")  
xml.root.attributes['test'] = '<'
xml.to_s    =>  "<root test='&lt' />"

#
# Use the output of this xml to create a new xml (reload saved data)
#
xml2 = REXML::Document.new( xml.to_s )
xml2.to_s   =>  "<root test='&amp;&lt;' />    

# I expect "xml2.to_s" to be "<root test='&lt' />"

The code above worked correctly in REXML 3.1.4

There's no problem with text nodes: <root>&lt;</root> works correctly. It only is broken in the attributes!


I think the cause is the code I found at line +/- 291 in text.rb:

  #copy = copy.gsub( EREFERENCE, '&amp;' )
  copy = copy.gsub( "&", "&amp;" )

I assume the first copy with EREFERENCE should be enabled not the "&" version! I've tried to changed it and it solved my problem!!

Change History

Changed 11 months ago by ser

  • milestone set to 3.1.8

Changed 11 months ago by ser

  • status changed from new to closed
  • resolution set to duplicate

This was fixed in release 3.1.7.

Note: See TracTickets for help on using tickets.