diff --git a/lib/nori.rb b/lib/nori.rb index ba55215..a1f3236 100644 --- a/lib/nori.rb +++ b/lib/nori.rb @@ -46,6 +46,8 @@ def parse(xml) parser = load_parser @options[:parser] parser.parse(cleaned_xml, @options) + rescue NoMethodError => e + raise ArgumentError, "Parsing error (#{e.message}), might be malformed xml" end private diff --git a/spec/nori/nori_spec.rb b/spec/nori/nori_spec.rb index 52c009f..36415e6 100644 --- a/spec/nori/nori_spec.rb +++ b/spec/nori/nori_spec.rb @@ -640,6 +640,10 @@ expect(parse(' ')).to eq({}) end + it "handle incorrect xml string" do + incorrect_xml = "\n\n 0\n\n" + expect { parse(incorrect_xml) }.to raise_error(ArgumentError, /Parsing error/) + end end end