0

So, I'm developing a simple URL shortener in Symfony2 - one of the things that is required is the input must be a valid URL.

So I've set everything up and it's being validated, but it doesn't validate the TLD! It will pass things through such as "A" as being a valid domain!

What's going on?

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
Joe McKie
  • 96
  • 1
  • 9
  • 2
    So you don't think `http://localhost` should pass? Something like `http://somedomain.a` or `http://x` **is a perfectly valid URI**. That's why it passes validation. Though it's not a duplicate, you might read [this answer](http://stackoverflow.com/a/12170188/895378) for more on URI validation. –  Sep 27 '12 at 14:02
  • "A" is valid domain. If I set up my local DNS to redirect http://a to 127.0.0.1 and if I set my Apache's (or whatever server I can use) VHOST to serve certain files for domain "A" - what's exactly wrong there? – N.B. Sep 27 '12 at 14:06
  • So something like "http://google/" should direct me to a website then apparently, cause as far as I always knew - you'd get an error from that. – Joe McKie Sep 27 '12 at 14:15

1 Answers1

4

You do not only want to validate the TLD, but also if the TLD is within the public suffix list:

Also please see a related question for a list of libraries: Get the subdomain from a URL

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836