Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every string without a period is parsed by addressable #43

Closed
gouravtiwari opened this issue Aug 5, 2011 · 2 comments
Closed

Every string without a period is parsed by addressable #43

gouravtiwari opened this issue Aug 5, 2011 · 2 comments

Comments

@gouravtiwari
Copy link

I would like to use addressable library to validate domain names users insert, but it is failing in my simple scenario, may be I am doing something wrong here:

C:>irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'uri'
=> true
irb(main):003:0> URI.parse('mic')
=> #<URI::Generic:0x4231f50 URL:mic>

How can I validate whether this string is a valid domain name?

@sporkmonger
Copy link
Owner

That's not Addressable. That's the URI implementation in the standard library. Load Addressable with:

require 'addressable/uri'
Addressable::URI.parse(uri_string)

However, Addressable does not verify domain names. Domain names are not part of the URI spec, so Addressable intentionally does not verify them. The URI implementation in the standard library partially validates them, but there are plenty of valid domains that it rejects and plenty of invalid ones that it misses, so I don't recommend using it for this purpose.

RFC 1123 covers the hostname format.

This question on StackOverflow is similar to what you seem to be looking for.

If you need to verify more than just whether the URI is valid, I'd recommend checking out the Google Site Verification API.

@sporkmonger
Copy link
Owner

Also, I should add that the strings you're entering are in fact relative URIs, not domain names as far as the parse methods of both Addressable and the standard library are concerned. So yes, these will all be parsed without error, and that is 100% the correct result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants