How to bypass illegal octal digit in url?

I have a method in my rails application that saves an image from the og: image url.

def photo_from_url(url) if !Nokogiri::HTML(open(url)).css("meta[property='og:image']").blank? photo_url = Nokogiri::HTML(open(url)).css("meta[property='og:image']").first.attributes["content"] self.photo = URI.parse(photo_url) self.save end end 

This works in most cases, unless the URL of the image includes a number starting with 0, for example http://ad009cdnb.website.com/rest-of-url

In these cases, I get an illegal octal digital error.

How can I stop the method from thinking that any numbers starting from zero are base-8?

+4
source share
2 answers

This is not an answer. Sorry for the malfunctioning system. It is impossible to learn how to put a string with HTTP without changing the link as a comment.

URI.parse works fine:

 URI.parse("http://ad009cdnb.website.com/rest-of-url").to_s => "http://ad009cdnb.website.com/rest-of-url" 

as everyone said, we really need a stack or something that will help you. And, most likely, you will want to save the URL as a string, and not as an object in the database.

+2
source

Hi guys, I posted this question, but I can no longer reproduce this question.

Since this is no longer a problem, I believe that the best way to do this is to close this question. However, I see that some people voted for their comments (they make good points, like saving as a string rather than an object). Will they be discredited if questions are closed?

I am grateful to everyone for their contribution and I do not want to upset anyone. What is the SO protocol for this situation?

+1
source

All Articles