diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rexml/parsers/sax2parser.rb | 6 | ||||
-rw-r--r-- | test/rexml/parser/test_sax2.rb | 24 |
3 files changed, 36 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sun Aug 11 18:08:40 2013 Kouhei Sutou <kou@cozmixng.org> + + * lib/rexml/parsers/sax2parser.rb (REXML::Parsers::SAX2Parser#parse): + Support NDATA in external entity declaration. + * test/rexml/parser/test_sax2.rb: Add tests for the above case. + Sun Aug 11 18:07:39 2013 Kouhei Sutou <kou@cozmixng.org> * lib/rexml/parsers/baseparser.rb diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb index d73daf7036..4a95bc6fff 100644 --- a/lib/rexml/parsers/sax2parser.rb +++ b/lib/rexml/parsers/sax2parser.rb @@ -177,6 +177,12 @@ module REXML handle( :characters, copy ) when :entitydecl @entities[ event[1] ] = event[2] if event.size == 3 + case event[2] + when "SYSTEM" + event[4, 0] = "NDATA" if event.size == 5 + when "PUBLIC" + event[5, 0] = "NDATA" if event.size == 6 + end handle( event[0], event[1..-1] ) when :processing_instruction, :comment, :attlistdecl, :elementdecl, :cdata, :notationdecl, :xmldecl diff --git a/test/rexml/parser/test_sax2.rb b/test/rexml/parser/test_sax2.rb index f1e64121af..a4279fa5d3 100644 --- a/test/rexml/parser/test_sax2.rb +++ b/test/rexml/parser/test_sax2.rb @@ -54,6 +54,18 @@ class TestSAX2Parser < Test::Unit::TestCase class TestExternlID < self class TestSystem < self + def test_with_ndata + declaration = [ + "name", + "SYSTEM", "system-literal", + "NDATA", "ndata-name", + ] + assert_equal([declaration], + parse(<<-INTERNAL_SUBSET)) +<!ENTITY name SYSTEM "system-literal" NDATA ndata-name> + INTERNAL_SUBSET + end + def test_without_ndata declaration = [ "name", @@ -67,6 +79,18 @@ class TestSAX2Parser < Test::Unit::TestCase end class TestPublic < self + def test_with_ndata + declaration = [ + "name", + "PUBLIC", "public-literal", "system-literal", + "NDATA", "ndata-name", + ] + assert_equal([declaration], + parse(<<-INTERNAL_SUBSET)) +<!ENTITY name PUBLIC "public-literal" "system-literal" NDATA ndata-name> + INTERNAL_SUBSET + end + def test_without_ndata declaration = [ "name", |