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

Feature request: URI Validation method that returns boolean #257

Closed
benSlaughter opened this issue Mar 3, 2017 · 5 comments
Closed

Feature request: URI Validation method that returns boolean #257

benSlaughter opened this issue Mar 3, 2017 · 5 comments

Comments

@benSlaughter
Copy link

Having come across an issue using ruby-json-schema, a discussion has been started here regarding parsing a URI using addressable, and managing failures and flow control with exceptions.
It was mentioned that having a method similar to parse that would validate a URI and return a boolean value if the URI was valid instead of raising an exception.

tl;dr Can we have a URI validation method please that returns a boolean value.

@dentarg
Copy link
Collaborator

dentarg commented Mar 3, 2017

having a method similar to parse that would validate a URI and return a boolean value if the URI was valid instead of raising an exception

This is actually what the gem twingly-url is doing, see https://github.com/twingly/twingly-url#getting-started for some examples. It might be useful for you, or give you some inspiration on how to wrap addressable yourself. twingly-url is using addressable and public_suffix under the covers. (Full disclosure: I work for the company that made twingly-url)

@benSlaughter
Copy link
Author

Nothing wrong with plugging your own gems ;)

Thanks for the response, I'm not the owner of the code with the issue, I was enquiring as I liked the idea of a non aggressive validation method.
I'll pass this on 👍

@RST-J
Copy link

RST-J commented Mar 15, 2017

Of course we can handle addressable's execption and wrap it internally in json-schema to get along. But as using exceptions for control flow is considered bad in general in programming (at least this is my perception), I thought it would be worth to raise this issue here at the root. And really no harm done if @sporkmonger looks at it and decides to leave things as they are. Its only about giving it a thought.

@sporkmonger
Copy link
Owner

As a matter of implementation, I agree that this should be a peer method to parse. As a matter of practicality, I think this would produce a massive maintenance load that I'm not prepared to take on. There's no particularly good definition of "validity" for URLs because most arbitrary strings are perfectly valid as URLs. There's a handful of strings that resolve to something invalid (e.g. URL with non-numeric port), but these are usually the result of a semantic failure rather than a syntactic failure. Addressable is focused primarily on the syntactic level, which is why it doesn't really try terribly hard to ascertain whether a URL makes sense or not. If someone wants to submit a PR and then commit to maintaining that code, I'm open to it, but I'd need a firm commitment to maintain or I would decline the PR.

@dentarg
Copy link
Collaborator

dentarg commented Oct 23, 2022

I'm going to close this one, and recommend use of https://github.com/twingly/twingly-url (or your own wrapper) if you want this. While it has a strange name (hehe) it does this and I think it does it well. I no longer work at Twingly but I still use it when I need to check if a URL is valid or not.

@dentarg dentarg closed this as completed Oct 23, 2022
@dentarg dentarg closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2022
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

4 participants