Skip to content

Thre are real world REXML::Document.new("") usages#296

Description

@kou

First of all, thanks for the work on this project. 馃檱

I'm noticing this handles empty string but not nil input.

In 3.4.2, they had the same behavior:

irb(main):003> REXML::Document.new("")
=> <UNDEFINED/>
irb(main):004> REXML::Document.new(nil)
=> <UNDEFINED/>

Now, in 3.4.3, the behavior is changed:

irb(main):002> REXML::Document.new("")
../.gem/ruby/3.3.9/gems/rexml-3.4.3/lib/rexml/parsers/baseparser.rb:271:in `pull_event': Malformed XML: No root element (REXML::ParseException)
Line: 0
Position: 0
Last 80 unconsumed characters:

	from ../.gem/ruby/3.3.9/gems/rexml-3.4.3/lib/rexml/parsers/baseparser.rb:249:in `pull'
	from ../.gem/ruby/3.3.9/gems/rexml-3.4.3/lib/rexml/parsers/treeparser.rb:21:in `parse'
	from ../.gem/ruby/3.3.9/gems/rexml-3.4.3/lib/rexml/document.rb:466:in `build'
	from ../.gem/ruby/3.3.9/gems/rexml-3.4.3/lib/rexml/document.rb:103:in `initialize'
	from (irb):2:in `new'
	from (irb):2:in `<main>'
	from <internal:kernel>:187:in `loop'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/cli/console.rb:16:in `run'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/cli.rb:482:in `console'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/vendor/thor/lib/thor.rb:538:in `dispatch'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/cli.rb:35:in `dispatch'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/lib/bundler/cli.rb:29:in `start'
	from ../.gem/ruby/3.3.9/gems/bundler-2.6.2/exe/bundle:28:in `block in <top (required)>'
	... 4 levels...
irb(main):003> REXML::Document.new(nil)
=> <UNDEFINED/>

Finally, should this print a warning in a patch release (3.4.x) and raise in the next minor release (3.5.x)? I noticed this because rexml hasn't validated this forever so there's possibly other code that was creating a document and adding elements later, see: https://github.com/search?q=REXML%3A%3ADocument.new%28%22%22%29&type=code

Thanks!

Originally posted by @jrafanie in #291 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions