Ticket #45 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Notation declarations are incorrectly parsed

Reported by: self@… Owned by: ser
Priority: normal Milestone: 3.1.4
Component: DOM Version: 3.1.2
Severity: normal Keywords: NotationDecl, Notation
Cc: Ruby version: Other
Operating system: Linux

Description (last modified by ser) (diff)

If a Doctype declaration contains two notation declarations, like this:

      <!NOTATION n1 PUBLIC "-//HM//NOTATION TEST1//EN" 'urn:x-henrikmartensson.org:test5'>

      <!NOTATION n2 PUBLIC '-//HM//NOTATION TEST2//EN' "urn:x-henrikmartensson.org:test6">

REXML will be confused after parsing the first declararation, and believe the second declaration is part of the first one.

The problem occurs only when one of the identifiers in a notation is enclosed in double quotes, and the other is enclosed in single quotes.

See the following unit test for an example:

#! /usr/bin/ruby

require 'test/unit'
require 'rexml/document'

# Mix in convenience methods in REXML classes
module REXML
  class NotationDecl
    def name
      @name
    end
  end
  
  class DocType
    def notations
      children().select {|node| node.kind_of?(REXML::NotationDecl)}
    end
    
    def notation(name)
      notations.find { |notation_decl|
        notation_decl.name == name
      }
    end
  end
end


class TestNotationDecl < Test::Unit::TestCase
  def setup
    doc_string = <<-'XMLEND'
    <!DOCTYPE r SYSTEM "urn:x-henrikmartensson:test" [
      <!NOTATION n1 PUBLIC "-//HM//NOTATION TEST1//EN" 'urn:x-henrikmartensson.org:test5'>
      <!NOTATION n2 PUBLIC '-//HM//NOTATION TEST2//EN' "urn:x-henrikmartensson.org:test6">
    ]>
    <r/>
    XMLEND
    @doctype = REXML::Document.new(doc_string).doctype
  end
  
  def test_notation
    assert(@doctype.notation('n1'), "Testing notation n1")
    assert(@doctype.notation('n2'), "Testing notation n2")
  end

end

Attachments

notationdecl_parsetest.rb (1.0 kB) - added by self@… 3 years ago.
Test case verifying incorrect parsing of notation declarations

Change History

Changed 3 years ago by self@…

Test case verifying incorrect parsing of notation declarations

Changed 3 years ago by ser

  • status changed from new to assigned

Excellent bug report.

Changed 3 years ago by ser

  • status changed from assigned to closed
  • resolution set to fixed
  • description modified (diff)

Fixed by changeset:1178.

The fix rewrites how notation declarations in DTDs are parsed, to be more correct. Most of the DTD parsing is still a hack, so these sorts of problems will continue to crop up. But, DTD stinks and I support it only reluctantly. In any case, notation declarations should be parsed correctly.

This reverts most of Hendrik's patch, since those changes were based on the parsing hack, but the API hasn't changed.

This change will be in milestone:3.1.4, and is in HEAD.

Note: See TracTickets for help on using tickets.