Ticket #96 (closed defect: fixed)

Opened 23 months ago

Last modified 14 months ago

UNILE file without XML declaration could not be parsed properly

Reported by: masa-ita Owned by: ser
Priority: normal Milestone: 3.1.8
Component: DOM Version: 3.1.6
Severity: major Keywords:
Cc: Ruby version: 1.8.5
Operating system: Windows

Description

An UNILE file with BOM and without xml declartion could not parsed properly.

The test:

$KCODE='u'
require "test/unit"
require "rexml/document"

class TestUnile < Test::Unit::TestCase
  def setup
    @file = File.new("UNILE.xml")
    @r = REXML::Document.new(@file).root
  end
  
  def test_create_document
    assert_equal("1stElement", @r.elements["FirstElement"].text, "FirstElement is 1stElement.")
  end
end

with test data:

<XMLroot>
<FirstElement>1stElement</FirstElement>
<SecondElement>
  <ChildOfSecond>ChildOfSecondElement</ChildOfSecond>
  <Child2 attr="MyAttribute">Child2</Child2>
  </SecondElement>
</XMLroot>

failed with error: REXML::ParseException?: #<RuntimeError?: attempted adding second root element to document>

My environment is as follows: ruby 1.8.4 (2006-04-14) [i386-mswin32] "3.1.6" "i386-mswin32"

It seems that the change in source.rb introduced this behaviour.

		def encoding=(enc)
			return unless super # << this change from 'super'
			@line_break = encode( '>' )
			if enc != UTF_8
				@buffer = decode(@buffer)
				@to_utf = true
			else
				@to_utf = false
			end
		end

Change History

Changed 16 months ago by ser

  • milestone set to Deferred

Please attach a test file encoded in UNILE.

Changed 14 months ago by ser

  • status changed from new to closed
  • resolution set to fixed
  • milestone changed from Deferred to 3.1.8

This is fixed in 3.1.7.2, and will be included in 3.1.8.

Note: See TracTickets for help on using tickets.