diff --git a/lib/html2text.rb b/lib/html2text.rb index d7ebd79..d672cbc 100644 --- a/lib/html2text.rb +++ b/lib/html2text.rb @@ -99,16 +99,20 @@ def iterate_over(node) output << prefix_whitespace(node) output += node.children.map do |child| - iterate_over(child) + if !child.name.nil? + iterate_over(child) + end end output << suffix_whitespace(node) output = output.compact.join("") || "" - if node.name.downcase == "a" - output = wrap_link(node, output) - elsif node.name.downcase == "img" - output = image_text(node) + if !node.name.nil? + if node.name.downcase == "a" + output = wrap_link(node, output) + elsif node.name.downcase == "img" + output = image_text(node) + end end return output diff --git a/spec/examples/malformed-style.html b/spec/examples/malformed-style.html new file mode 100644 index 0000000..94d105d --- /dev/null +++ b/spec/examples/malformed-style.html @@ -0,0 +1,52 @@ + + + + title + + + + +

Some body

+ + \ No newline at end of file diff --git a/spec/examples/malformed-style.txt b/spec/examples/malformed-style.txt new file mode 100644 index 0000000..f35554d --- /dev/null +++ b/spec/examples/malformed-style.txt @@ -0,0 +1 @@ +Some body \ No newline at end of file