Skip to content

Commit

Permalink
fix #1005. fix a regression introduced in eebfda0
Browse files Browse the repository at this point in the history
Parsing empty documents should raise a SyntaxError when strict parsing
is turned on
  • Loading branch information
jvshahid committed Nov 20, 2013
1 parent d68dd48 commit 2c9b7f1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.ja.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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日

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/xml/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<? ?>'
Expand Down

0 comments on commit 2c9b7f1

Please sign in to comment.