From c3b702db1c48de3cc68166ec197081c63ff10dda Mon Sep 17 00:00:00 2001 From: NAITOH Jun Date: Sun, 21 Sep 2025 08:26:16 +0900 Subject: [PATCH] Fixed an issue when executing `REXML::Parsers::SAX2Parser#parse` without specifying `#listen` ``` > require 'rexml/parsers/sax2parser' > REXML::Parsers::SAX2Parser.new("").parse lib/rexml/parsers/sax2parser.rb:263:in 'REXML::Parsers::SAX2Parser#get_namespace': undefined method '[]' for nil (NoMethodError) current_namespace[prefix] || current_namespace[nil] ^^^^^^^^ from lib/rexml/parsers/sax2parser.rb:150:in 'REXML::Parsers::SAX2Parser#parse' ``` --- lib/rexml/parsers/sax2parser.rb | 2 +- test/test_sax.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb index 79838528..f12494d3 100644 --- a/lib/rexml/parsers/sax2parser.rb +++ b/lib/rexml/parsers/sax2parser.rb @@ -157,7 +157,7 @@ def parse ob.end_element( uri, local, event[1] ) } if listeners - namespace_mapping = @namespace_stack.pop + namespace_mapping = @namespace_stack.pop if procs or listeners # find the observers for namespaces procs = get_procs( :end_prefix_mapping, event[1] ) listeners = get_listeners( :end_prefix_mapping, event[1] ) diff --git a/test/test_sax.rb b/test/test_sax.rb index caec983b..9fa27713 100644 --- a/test/test_sax.rb +++ b/test/test_sax.rb @@ -7,6 +7,12 @@ module REXMLTests class SAX2Tester < Test::Unit::TestCase include Helper::Fixture include REXML + + def test_without_listien + p = Parsers::SAX2Parser.new "" + p.parse + end + def test_characters d = Document.new( "@blah@" ) txt = d.root.text