Skip to content

Commit

Permalink
fix 'undefined method for nil:NilClass' on wrong xmls
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Zagaynov authored and Alexander Zagaynov committed Jul 1, 2020
1 parent 5977170 commit 58c5f35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/nori.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def parse(xml)

parser = load_parser @options[:parser]
parser.parse(cleaned_xml, @options)
rescue NoMethodError => e
raise ArgumentError, "Parsing error, might be malformed xml"
end

private
Expand Down
5 changes: 5 additions & 0 deletions spec/nori/nori_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@
expect(parse(' ')).to eq({})
end


it "handle incorrect xml string" do
incorrect_xml = "<?xml version=\"1.0\" encoding=\"utf-8\">\n<request>\n <opcode>0</opcode>\n</request>\n"
expect { parse(incorrect_xml) }.to raise_error(ArgumentError, /Parsing error/)
end
end
end

Expand Down

0 comments on commit 58c5f35

Please sign in to comment.