Skip to content

Instantly share code, notes, and snippets.

@caius
Created July 15, 2013 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caius/6002173 to your computer and use it in GitHub Desktop.
Save caius/6002173 to your computer and use it in GitHub Desktop.
require "uri"
urls = [
"http://caius.name/",
"http:/caius.name/",
"http://ca]ius.name/",
"http://cai;us.name/",
"http://caius",
"http://",
"caius.name",
]
headers = %w(url pass-regex? pass-parse?)
i = (headers | urls).map {|x| x.length }.max
headers.each do |h|
printf " %-#{i}s", h
end
puts
urls.each do |u|
printf " %-#{i+5}s", u
if u =~ URI.regexp
printf " %-#{i}s", "βœ“"
else
printf " %-#{i}s", "𐄂"
end
begin
URI(u)
printf " %-#{i}s", "βœ“"
rescue URI::InvalidURIError => e
printf " %-#{i}s", "𐄂"
end
puts
end
# >> url pass-regex? pass-parse?
# >> http://caius.name/ βœ“ βœ“
# >> http:/caius.name/ βœ“ βœ“
# >> http://ca]ius.name/ βœ“ 𐄂
# >> http://cai;us.name/ βœ“ 𐄂
# >> http://caius βœ“ βœ“
# >> http:// βœ“ 𐄂
# >> caius.name 𐄂 βœ“
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment