I use uri? predicate to validate whether a string is an valid URI. However, this case fails:
schema = Dry::Schema.JSON do
required(:picture_url).filled(:string, uri?: 'https')
end
schema.call(picture_url: '{https://picture.com/some_image.png}')
# => return successful, while it should be failed.
Upon reading code of URI module, I notice that URI::DEFAULT_PARSER.make_regexp creates a regex that matches only part of the string, and I have no way to avoid that behavior, aside from switching to URI::RFC3986_Parser::RFC3986_URI:
schema = Dry::Schema.JSON do
required(:picture_url).filled(:string, format?: URI::RFC3986_Parser::RFC3986_URI)
end
However, this prevent me from using the nice error message that comes with uri? predicate. I suppose some people would have the same problems as me, so I would like to contribute it back to the repo.
I understand that changing uri? itself would be a breaking change, so I want to avoid that, and add a new uri_rfc3986? predicate instead. If people start using it over uri?, maybe we can consider deprecate uri? and replace it with uri_rfc3986? in v2.0.
I use
uri?
predicate to validate whether a string is an valid URI. However, this case fails:Upon reading code of
URI
module, I notice thatURI::DEFAULT_PARSER.make_regexp
creates a regex that matches only part of the string, and I have no way to avoid that behavior, aside from switching toURI::RFC3986_Parser::RFC3986_URI
:However, this prevent me from using the nice error message that comes with
uri?
predicate. I suppose some people would have the same problems as me, so I would like to contribute it back to the repo.I understand that changing
uri?
itself would be a breaking change, so I want to avoid that, and add a newuri_rfc3986?
predicate instead. If people start using it overuri?
, maybe we can consider deprecateuri?
and replace it withuri_rfc3986?
in v2.0.