Project

General

Profile

Feature #12867

Add ability to check validity of a URL

Added by shlok007 (Shlok Srivastava) over 2 years ago. Updated over 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:77722]

Description

Hi!
Going through the URI module of Ruby, it was obvious that we can check the validity of a URI by using URI.regexp . However, I found out there is no way we can accurately check for a valid URL by using the URI module. Won't it be better if there was a built in method in the URI module that could check for the validity of a URL or a URN as well ?

This is just a suggestion and feel free to close it if this doesn't seems like something that should be implemented. :)

PS- If you feel this can or should be implemented, I would love to work on it. ;)
Thank you.

History

Updated by simplybe (Theresa May) over 2 years ago

I'd also love to work on this for my project over at the Fuss / Simply be http://www.thefuss.co.uk/simply-contact-number

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

Doesn't URI.parse work for you?

Updated by shlok007 (Shlok Srivastava) over 2 years ago

Shyouhei Urabe wrote:

Doesn't URI.parse work for you?

As URI.parse actually check for valid URIs and not URLs

I tried something like this:

URI.parse(some_string).scheme == "http"

But it returns true for invalid URLs which seem to be valid URIs ( Example: http:invalid-url )

Updated by phluid61 (Matthew Kerwin) over 2 years ago

Shlok Srivastava wrote:

Shyouhei Urabe wrote:

Doesn't URI.parse work for you?

As URI.parse actually check for valid URIs and not URLs

I tried something like this:

URI.parse(some_string).scheme == "http"

But it returns true for invalid URLs which seem to be valid URIs ( Example: http:invalid-url )

http:invalid-url is invalid according to the scheme-specific definition in RFC7230, but is valid and parses according to RFC3986. Depending on one's viewpoint, there's either no way to know whether or not a given URI is a URL/URN without implementing that particular scheme's specification, or all URIs are URLs except for those in the "urn:" scheme. And without implementing a scheme's spec, there's no way to know whether a given URI (which is valid according to RFC3986) is valid for that scheme.

So from that I infer that you either want a general scheme-aware validator, or you want a http(s)-specific validator. Is that correct? And if so, which is it? Will you ever want to validate (s)ftp URIs? Or mailto? Or xmpp? Or file? etc. all of which are URL schemes.

Also available in: Atom PDF