Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9d258f6f1a04
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cb9a2930fb36
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Jun 5, 2016

  1. Fix problem of XML parsing empty html string. Fixes #2752

    Raise an exception when XML.parse_html called with empty string.
    fernandes committed Jun 5, 2016
    Copy the full SHA
    ebd4f3e View commit details

Commits on Jun 6, 2016

  1. Merge pull request #2759 from fernandes/fix/xml_parse_empty_string

    Fix problem of XML parsing empty html string. Fixes #2752
    Ary Borenszweig committed Jun 6, 2016
    Copy the full SHA
    cb9a293 View commit details
Showing with 14 additions and 0 deletions.
  1. +6 −0 spec/std/xml/html_spec.cr
  2. +6 −0 spec/std/xml/xml_spec.cr
  3. +2 −0 src/xml/xml.cr
6 changes: 6 additions & 0 deletions spec/std/xml/html_spec.cr
Original file line number Diff line number Diff line change
@@ -63,4 +63,10 @@ describe XML do
xml.errors.should_not be_nil
xml.xpath_node("//html/body/nav").should_not be_nil
end

it "raises error when parsing empty string (#2752)" do
expect_raises XML::Error, "Document is empty" do
XML.parse_html("")
end
end
end
6 changes: 6 additions & 0 deletions spec/std/xml/xml_spec.cr
Original file line number Diff line number Diff line change
@@ -96,6 +96,12 @@ describe XML do
person["id"].should eq("1")
end

it "raises exception on empty string" do
expect_raises XML::Error, "Document is empty" do
XML.parse("")
end
end

it "does to_s" do
string = <<-XML
<?xml version='1.0' encoding='UTF-8'?>\
2 changes: 2 additions & 0 deletions src/xml/xml.cr
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ module XML
# Parses an XML document from *string* with *options* into an `XML::Node`.
# See `ParserOptions.default` for default options.
def self.parse(string : String, options : ParserOptions = ParserOptions.default) : Node
raise XML::Error.new("Document is empty", 0) if string.empty?
from_ptr LibXML.xmlReadMemory(string, string.bytesize, nil, nil, options)
end
@@ -63,6 +64,7 @@ module XML
# Parses an HTML document from *string* with *options* into an `XML::Node`.
# See `HTMLParserOptions.default` for default options.
def self.parse_html(string : String, options : HTMLParserOptions = HTMLParserOptions.default) : Node
raise XML::Error.new("Document is empty", 0) if string.empty?
from_ptr LibXML.htmlReadMemory(string, string.bytesize, nil, nil, options)
end