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

URI validation #171

Open
jameshensmancitrix opened this issue May 4, 2023 · 4 comments
Open

URI validation #171

jameshensmancitrix opened this issue May 4, 2023 · 4 comments

Comments

@jameshensmancitrix
Copy link

I am currently trying to use Uri.of_string as an assertion that a url input is valid, however I have learned this is not the case. Is there a way to validate urls within this library, it would be a useful utility and avoid having to regex directly for this.

@lindig
Copy link

lindig commented May 4, 2023

https://github.com/mirage/ocaml-uri/blob/master/lib/uri.ml#L1105-L1112

This is the implementation of of_string and it looks like it would accept all strings. Maybe adding a predicate like is_valid or validate to the interface could support this use case.

@avsm
Copy link
Member

avsm commented May 4, 2023

You haven't elaborated on your usecase, but you could just do a Uri.of/to_string roundtrip and compare with the original string, if performance is not an issue.

@lindig
Copy link

lindig commented May 4, 2023

The use case is to validate the syntax of a URI. Granted. a lot of strings are a valid URI but might still not match the expectation because, for example, the scheme is valid but unexpected.

@jameshensmancitrix
Copy link
Author

jameshensmancitrix commented May 4, 2023

The use case is validation of user inputed url strings which are going to be used to send information to. By doing this with an empty string you would have it return true Uri.of_string "" |> Uri.to_string will return "" this is case where we would consider this an invalid url. of_string takes in url strings which could generally be considered no urls such as "http:/localhost" which has incorrect syntax for the scheme. Performance in this case is not critical as it is related to user input validation, and at that is unlikely to be done much or on many urls at once.

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

3 participants