Skip to content

Commit 58c5f35

Browse files
Alexander ZagaynovAlexander Zagaynov
Alexander Zagaynov
authored and
Alexander Zagaynov
committed
fix 'undefined method for nil:NilClass' on wrong xmls
1 parent 5977170 commit 58c5f35

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/nori.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def parse(xml)
4646

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

5153
private

spec/nori/nori_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,11 @@
640640
expect(parse(' ')).to eq({})
641641
end
642642

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

0 commit comments

Comments
 (0)