REXML bug?

M

Makoto Kuwata

Hi,

I have got an error around REXML.
I think there is a bug in REXML::Doctype#write().

Sample program :
------------------------------------------------------------
require 'rexml/document'

## XML Document and Declaration
document = REXML::Document.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::DocType.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
 
S

Sean Russell

Makoto Kuwata said:
I have got an error around REXML.
I think there is a bug in REXML::Doctype#write().

I'll check it out, but I probably won't be able to get to it until tomorrow.

Would you please post the output from:

ruby -rrexml/rexml -ve 'puts REXML::Version'

Thanks.

--- SER
 
S

Sean Russell

Makoto Kuwata said:
I have got an error around REXML.
I think there is a bug in REXML::Doctype#write().

Yes, this was a bug in Doctype; it should be fixed in the current
release of REXML, as well as in CVS; in fact, it has been fixed for a
couple of months -- I believe ti got fixed in version 3.0.2, so I'm
curious which version of REXML and Ruby you're running.

--- SER
 
M

Makoto Kuwata

Sorry for late reply.
Here is the result:

$ ruby -rrexml/rexml -ve 'puts REXML::Version'
ruby 1.8.1 (2004-01-01) [i686-linux-gnu]
2.7.3

I think it is a version which is bundled with Ruby1.8.1.

And I download and installed REXML 3.0.4, but I got the
same error at the same position.

===================================================================
$ ruby -rrexml/rexml -ve 'puts REXML::Version'
ruby 1.8.1 (2004-01-01) [i686-linux-gnu]
3.0.4
$ ruby hoge.rb
/usr/lib/ruby/site_ruby/1.8/rexml/doctype.rb:114:in `write': undefined method `e
mpty?' for nil:NilClass (NoMethodError)
from /usr/lib/ruby/site_ruby/1.8/rexml/document.rb:162:in `write'
from /usr/lib/ruby/site_ruby/1.8/rexml/document.rb:160:in `each'
from /usr/lib/ruby/site_ruby/1.8/rexml/document.rb:160:in `write'
from hoge.rb:21
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE
===================================================================

See the previous mail I send for details of the test script.
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Re: REXML bug?" on Thu, 6 May 2004 22:29:09 +0900,
Yes, this was a bug in Doctype; it should be fixed in the current
release of REXML, as well as in CVS; in fact, it has been fixed for a
couple of months -- I believe ti got fixed in version 3.0.2, so I'm

It seems to be not fixed. REXML::Docutype#initialize doesn't
call `super' when `first' is REXML::Source.

I attach a patch for the bug, but I don't like this
solution. :( I hope SER supply more flexible solution.

--
kou

Index: lib/rexml/doctype.rb
===================================================================
RCS file: /src/ruby/lib/rexml/doctype.rb,v
retrieving revision 1.5
diff -u -p -b -r1.5 doctype.rb
--- lib/rexml/doctype.rb 28 Mar 2004 22:36:15 -0000 1.5
+++ lib/rexml/doctype.rb 7 May 2004 13:23:53 -0000
@@ -54,6 +54,15 @@ module REXML
@external_id = first[1]
@long_name = first[2]
@uri = first[3]
+ elsif first.kind_of? Source
+ super()
+ parser = Parsers::BaseParser.new( first )
+ event = parser.pull
+ if event[0] == :start_doctype
+ @name, @external_id, @long_name, @uri, = event[1..-1]
+ end
+ else
+ super()
end
end
 
S

Sean Russell

Kouhei Sutou said:
It seems to be not fixed. REXML::Docutype#initialize doesn't
call `super' when `first' is REXML::Source.

Yeah, I haven't had time to work in it. I got married this weekend
instead of working on Ruby projects. Diversity is always good.

I'll get a fix in shortly. Sorry for the delay.

--- SER
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top