From 2c9b7f1000b4870aa285e3c813f2de8c92593322 Mon Sep 17 00:00:00 2001 From: John Shahid Date: Wed, 20 Nov 2013 02:05:22 -0500 Subject: [PATCH] fix #1005. fix a regression introduced in eebfda0 Parsing empty documents should raise a SyntaxError when strict parsing is turned on --- CHANGELOG.ja.rdoc | 1 + CHANGELOG.rdoc | 1 + lib/nokogiri/xml/document.rb | 2 +- test/xml/test_document.rb | 7 +++++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.ja.rdoc b/CHANGELOG.ja.rdoc index ae3d1119ec0..e6ef3c22247 100644 --- a/CHANGELOG.ja.rdoc +++ b/CHANGELOG.ja.rdoc @@ -24,6 +24,7 @@ * (JRuby) XSD validation crashes in Java version. #373 * (JRuby) Document already has a root node error while using Builder. #646 * (JRuby) c14n tests are all passing on JRuby. #226 + * Parsing empty documents raise SyntaxError in strict mode. #1005 === 1.6.0 / 2013年6月8日 diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index e4e3a6bc9bd..691f07148b1 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -36,6 +36,7 @@ * (JRuby) XSD validation crashes in Java version. #373 * (JRuby) Document already has a root node error while using Builder. #646 * (JRuby) c14n tests are all passing on JRuby. #226 + * Parsing empty documents raise SyntaxError in strict mode. #1005 === 1.6.0 / 2013-06-08 diff --git a/lib/nokogiri/xml/document.rb b/lib/nokogiri/xml/document.rb index 7ac42e82fbf..6457cab4c5a 100644 --- a/lib/nokogiri/xml/document.rb +++ b/lib/nokogiri/xml/document.rb @@ -45,7 +45,7 @@ def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions:: # Give the options to the user yield options if block_given? - return new if empty_doc?(string_or_io) + return new if !options.strict? && empty_doc?(string_or_io) doc = if string_or_io.respond_to?(:read) url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil diff --git a/test/xml/test_document.rb b/test/xml/test_document.rb index 635ccedbfd4..09da2462547 100644 --- a/test/xml/test_document.rb +++ b/test/xml/test_document.rb @@ -26,6 +26,13 @@ def test_dtd_with_empty_internal_subset assert doc.root end + # issue #1005 + def test_strict_parsing_empty_doc_should_raise_exception + assert_raises(SyntaxError) do + Nokogiri::XML(StringIO.new('')) { |c| c.strict } + end + end + # issue #838 def test_document_with_invalid_prolog doc = Nokogiri::XML ''