phillipsm / pyfav

pyfav is a simple Python library that helps you get a favicon for a supplied URL.
13 stars 13 forks source link

Indirect (?) links #3

Open tlc opened 8 years ago

tlc commented 8 years ago

I'm handling a yahoo RSS stream with urls like this:

http://us.rd.yahoo.com/finance/external/xzdnet/rss/SIG=12nbpkhsr/*http://www.zdnet.com/article/bt-attains-5gbps-over-next-gen-g-fast/%23ftag=YHFb1d24ec

Using get_favicon_url(), I always get the yahoo icon, not the other one. But browsing to that URL I go to the second one. When I look with curl, I see a 302 redirect.

tlc commented 8 years ago

I solved by calling

r = requests.head(url, allow_redirects=True)
 url = r.url

before calling get_favicon_url().

Any chance of restricting types? My app can't handle SVG.

apelykh commented 8 years ago

I'm looking at download_favicon() and it seems that your check for valid characters isn't working.

valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
sanitized_filename = "".join([x if valid_chars else "" for x in favicon_filename])

if valid_chars condition is always True, so won't actually filter anything.