Ticket #1 (closed defect: wontfix)

Opened 3 years ago

Last modified 2 years ago

REXML::Document.new() raises REXML::ParseException

Reported by: Agt Owned by: ser
Priority: normal Milestone: 3.1.4
Component: DOM Version: 3.1
Severity: normal Keywords:
Cc: Ruby version: 1.8.2
Operating system: Linux

Description (last modified by ser) (diff)

REXML::Document.new doesn't accept "<a x:foo='1' y:foo='2'/>" for some reason :(

$ irb
irb(main):001:0> require 'rexml/document'
=> true
irb(main):002:0> REXML::Document.new "<a foo='3' x:foo='1'
y:foo='2'/>"
=> <UNDEFINED> ... </>
irb(main):003:0> REXML::Document.new "<a foo='3'/>"
=> <UNDEFINED> ... </>
irb(main):004:0> REXML::Document.new "<a x:foo='1' y:foo='2'/>"
REXML::ParseException: #<REXML::ParseException: Namespace
conflict in adding attribute "foo": Prefix "x" = "" and prefix "y" = "">
/usr/local/lib/ruby/1.8/rexml/element.rb:1094:in `[]='
/usr/local/lib/ruby/1.8/rexml/element.rb:280:in `add_element'
/usr/local/lib/ruby/1.8/rexml/element.rb:279:in `each'
/usr/local/lib/ruby/1.8/rexml/element.rb:279:in `add_element'
/usr/local/lib/ruby/1.8/rexml/document.rb:88:in `add_element'
/usr/local/lib/ruby/1.8/rexml/parsers/treeparser.rb:28:in `parse'
/usr/local/lib/ruby/1.8/rexml/document.rb:176:in `build'
/usr/local/lib/ruby/1.8/rexml/document.rb:45:in `initialize'
(irb):4:in `new'
(irb):4:in `irb_binding'
/usr/local/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
/usr/local/lib/ruby/1.8/irb/workspace.rb:52
...
Namespace conflict in adding attribute "foo": Prefix "x" =
"" and prefix "y" = "
"
Line: 
Position: 
Last 80 unconsumed characters:

        from
/usr/local/lib/ruby/1.8/rexml/parsers/treeparser.rb:85:in `parse'
        from
/usr/local/lib/ruby/1.8/rexml/document.rb:176:in `build'
        from /usr/local/lib/ruby/1.8/rexml/document.rb:45:in `initialize'
        from (irb):4:in `new'
        from (irb):4

Change History

Changed 3 years ago by ser

  • version set to 3.1
  • description modified (diff)

Changed 3 years ago by ser

  • status changed from new to closed
  • resolution set to wontfix
  • os set to Linux
  • description modified (diff)
  • ruby_version set to 1.8.2

The example XML is malformed, and REXML is correct in throwing an exception. It would be preferable if REXML threw an "undeclared namespace" exception, because this is the real reason the XML is malformed; instead, it is assuming both the "x" and "y" prefixes point to the empty namespace "", and it is invalid XML to specify two attributes of the same tag with the same name and namespace.

Note: See TracTickets for help on using tickets.