ruby-changes:30439
From: kou <ko1@a...>
Date: Sun, 11 Aug 2013 18:41:35 +0900 (JST)
Subject: [ruby-changes:30439] kou:r42518 (trunk): * lib/rexml/parsers/sax2parser.rb (REXML::Parsers::SAX2Parser#parse):
kou 2013-08-11 18:41:29 +0900 (Sun, 11 Aug 2013) New Revision: 42518 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42518 Log: * lib/rexml/parsers/sax2parser.rb (REXML::Parsers::SAX2Parser#parse): Fix wrong "%" position in parameter entity declaration event argument. * test/rexml/parser/test_sax2.rb: Add tests for the above case. Modified files: trunk/ChangeLog trunk/lib/rexml/parsers/sax2parser.rb trunk/test/rexml/parser/test_sax2.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42517) +++ ChangeLog (revision 42518) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Aug 11 18:40:25 2013 Kouhei Sutou <kou@c...> + + * lib/rexml/parsers/sax2parser.rb (REXML::Parsers::SAX2Parser#parse): + Fix wrong "%" position in parameter entity declaration event argument. + * test/rexml/parser/test_sax2.rb: Add tests for the above case. + Sun Aug 11 18:08:40 2013 Kouhei Sutou <kou@c...> * lib/rexml/parsers/sax2parser.rb (REXML::Parsers::SAX2Parser#parse): Index: lib/rexml/parsers/sax2parser.rb =================================================================== --- lib/rexml/parsers/sax2parser.rb (revision 42517) +++ lib/rexml/parsers/sax2parser.rb (revision 42518) @@ -177,12 +177,28 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/parsers/sax2parser.rb#L177 handle( :characters, copy ) when :entitydecl @entities[ event[1] ] = event[2] if event.size == 3 + parameter_reference_p = false case event[2] when "SYSTEM" - event[4, 0] = "NDATA" if event.size == 5 + if event.size == 5 + if event.last == "%" + parameter_reference_p = true + else + event[4, 0] = "NDATA" + end + end when "PUBLIC" - event[5, 0] = "NDATA" if event.size == 6 + if event.size == 6 + if event.last == "%" + parameter_reference_p = true + else + event[5, 0] = "NDATA" + end + end + else + parameter_reference_p = (event.size == 4) end + event[1, 0] = event.pop if parameter_reference_p handle( event[0], event[1..-1] ) when :processing_instruction, :comment, :attlistdecl, :elementdecl, :cdata, :notationdecl, :xmldecl Index: test/rexml/parser/test_sax2.rb =================================================================== --- test/rexml/parser/test_sax2.rb (revision 42517) +++ test/rexml/parser/test_sax2.rb (revision 42518) @@ -103,6 +103,47 @@ class TestSAX2Parser < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rexml/parser/test_sax2.rb#L103 end end end + + class TestParameterEntity < self + class TestValue < self + def test_double_quote + assert_equal([["%", "name", "value"]], parse(<<-INTERNAL_SUBSET)) +<!ENTITY % name "value"> + INTERNAL_SUBSET + end + + def test_single_quote + assert_equal([["%", "name", "value"]], parse(<<-INTERNAL_SUBSET)) +<!ENTITY % name 'value'> + INTERNAL_SUBSET + end + end + + class TestExternlID < self + def test_system + declaration = [ + "%", + "name", + "SYSTEM", "system-literal", + ] + assert_equal([declaration], + parse(<<-INTERNAL_SUBSET)) +<!ENTITY % name SYSTEM "system-literal"> + INTERNAL_SUBSET + end + + def test_public + declaration = [ + "%", + "name", + "PUBLIC", "public-literal", "system-literal", + ] + assert_equal([declaration], parse(<<-INTERNAL_SUBSET)) +<!ENTITY % name PUBLIC "public-literal" "system-literal"> + INTERNAL_SUBSET + end + end + end end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/