From e7ac3489db5eec4e09c2e032d49bf10cfe0a711e Mon Sep 17 00:00:00 2001 From: Leo Arnold Date: Tue, 26 Aug 2025 21:49:13 +0200 Subject: [PATCH] Fix ParseError when String has no trailing newline character --- lib/rexml/source.rb | 2 +- test/test_document.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index 99500072..9677e1be 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -258,7 +258,7 @@ def read(term = nil, min_bytes = 1) end true rescue Exception, NameError - @source = nil + @source = StringIO.new false end end diff --git a/test/test_document.rb b/test/test_document.rb index 39b6c337..9632a709 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -159,6 +159,12 @@ def test_xml_declaration_standalone assert_equal('no', doc.stand_alone?, bug2539) end + def test_no_trailing_newline + assert_nothing_raised do + REXML::Document.new("\n\n") + end + end + def test_each_recursive xml_source = <<~XML