jaimeiniesta / metainspector

Ruby gem for web scraping purposes. It scrapes a given URL, and returns you its title, meta description, meta keywords, links, images...
https://github.com/metainspector/metainspector
MIT License
1.04k stars 165 forks source link

images.best sometimes fails with undefined method `start_with?' for nil:NilClass (NoMethodError) #359

Open Aqualon opened 1 year ago

Aqualon commented 1 year ago
m = MetaInspector.new('https://karriere.westfalen.com/job/M%C3%BCnster-HR-Business-Partner-(mwd)/920832901/')
m.images.best

raises

/gems/fastimage-2.2.6/lib/fastimage.rb:235:in `initialize': undefined method `start_with?' for nil:NilClass (NoMethodError)

This happens in https://github.com/metainspector/metainspector/blob/35e3e75875ecbbb56fb7b0a5c17adc69baed1cb3/lib/meta_inspector/parsers/images.rb#L44-L47 because MetaInspector passes a nil URL to FastImage.size. The imgs_with_size variable looks like this for the failing URL.

[["https://rmkcdn.successfactors.com/241be56e/a93393ca-2eac-4e3c-b06e-e.png", nil, nil], [nil, nil, nil]]
Aqualon commented 1 year ago

Figure out, that this is a changed behavior in fastimage 2.2.2 onwards.

jaimeiniesta commented 1 year ago

Thanks for the bug report @Aqualon !

I'll have a look when I find some time, feel free to send a PR to fix that if you feel so inclined :)