added URL validation to webpage part
parent
72f3e03edd
commit
144731062b
14
app.rb
14
app.rb
|
|
@ -34,6 +34,20 @@ class App < Roda
|
||||||
flash['message'] = "Please enter a valid URL";
|
flash['message'] = "Please enter a valid URL";
|
||||||
r.redirect '/'
|
r.redirect '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
OpenURI.open_uri(url)
|
||||||
|
rescue URI::BadURIError
|
||||||
|
flash['message'] = "Invalid URL"
|
||||||
|
r.redirect '/'
|
||||||
|
rescue OpenURI::HTTPError
|
||||||
|
flash['message'] = "URL not found"
|
||||||
|
r.redirect '/'
|
||||||
|
rescue SocketError => e
|
||||||
|
flash['message'] = "URL does not resolve"
|
||||||
|
r.redirect '/'
|
||||||
|
end
|
||||||
|
|
||||||
if links.filter(:url => url).first.nil?
|
if links.filter(:url => url).first.nil?
|
||||||
code = SecureRandom.urlsafe_base64 4
|
code = SecureRandom.urlsafe_base64 4
|
||||||
links.insert(url: url, code: code)
|
links.insert(url: url, code: code)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue