M
Makoto Kuwata
Hi,
I have got an error around REXML.
I think there is a bug in REXML:octype#write().
Sample program :
------------------------------------------------------------
require 'rexml/document'
## XML Document and Declaration
document = REXML:ocument.new
xmldecl = REXML::XMLDecl.new("1.0", "UTF-8")
document.add(xmldecl)
## XML Doctype
str = '<!DOCTYPE foo "bar">'
source = REXML::Source.new(str)
doctype = REXML:ocType.new(source)
document.add(doctype)
## Element
element = REXML::Element.new("hoge")
document.add(element)
## print
document.write
------------------------------------------------------------
Result :
============================================================
$ ruby -v
ruby 1.8.1 (2004-01-01) [i686-linux-gnu]
$ ruby hoge.rb
/usr/lib/ruby/1.8/rexml/doctype.rb:111:in `write': undefined method `empty?' for
nil:NilClass (NoMethodError)
from /usr/lib/ruby/1.8/rexml/document.rb:159:in `write'
from /usr/lib/ruby/1.8/rexml/document.rb:157:in `each'
from /usr/lib/ruby/1.8/rexml/document.rb:157:in `write'
from hoge.rb:21
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE
============================================================
I read source codes of REXML and found that 'parent.rb' and
'doctype.rb' are not matched about '@children'.
------------------------------------------------------------
## rexml/parent.rb :
module REXML
class Parent < Child
....
def initalize parent=nil
super(parent)
@children = [] ## expected to be not nil
end
....
end
end
## rexml/doctype.rb :
module REXML
class DocType < Parent
def initialize( first, parent=nil )
....
super( parent ) ## set @children to nil
@name = first.name
@external_id = first.external_id
....
end
....
def write( output, indent=0, transitive=false, ie_hack=false )
....
unless @children.empty? ## ERROR!
....
end
....
end
end
end
I have got an error around REXML.
I think there is a bug in REXML:octype#write().
Sample program :
------------------------------------------------------------
require 'rexml/document'
## XML Document and Declaration
document = REXML:ocument.new
xmldecl = REXML::XMLDecl.new("1.0", "UTF-8")
document.add(xmldecl)
## XML Doctype
str = '<!DOCTYPE foo "bar">'
source = REXML::Source.new(str)
doctype = REXML:ocType.new(source)
document.add(doctype)
## Element
element = REXML::Element.new("hoge")
document.add(element)
document.write
------------------------------------------------------------
Result :
============================================================
$ ruby -v
ruby 1.8.1 (2004-01-01) [i686-linux-gnu]
$ ruby hoge.rb
/usr/lib/ruby/1.8/rexml/doctype.rb:111:in `write': undefined method `empty?' for
nil:NilClass (NoMethodError)
from /usr/lib/ruby/1.8/rexml/document.rb:159:in `write'
from /usr/lib/ruby/1.8/rexml/document.rb:157:in `each'
from /usr/lib/ruby/1.8/rexml/document.rb:157:in `write'
from hoge.rb:21
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE
============================================================
I read source codes of REXML and found that 'parent.rb' and
'doctype.rb' are not matched about '@children'.
------------------------------------------------------------
## rexml/parent.rb :
module REXML
class Parent < Child
....
def initalize parent=nil
super(parent)
@children = [] ## expected to be not nil
end
....
end
end
## rexml/doctype.rb :
module REXML
class DocType < Parent
def initialize( first, parent=nil )
....
super( parent ) ## set @children to nil
@name = first.name
@external_id = first.external_id
....
end
....
def write( output, indent=0, transitive=false, ie_hack=false )
....
unless @children.empty? ## ERROR!
....
end
....
end
end
end