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
Validate the scheme in a separate method of URLValidator #9991
Conversation
I'm hoping this is trivial enough to land in Django 2.1? |
The feature freeze for 2.1 is past. A Trac ticket, test, and documentation are also required. |
@timgraham I was following the lead of EmailValidator.validate_domain_part(). Not trying to implement a new public API. IMO this is a trivial refactoring, not a new feature. Although I would use it in django-oauth-toolkit, that would be with full understanding that it's a private API. I can lead it with an underscore if it helps? The method is already tested as well. |
If it's not a public API, then I don't see the advantage of put a simple condition in a separate method. We wouldn't refactor this if not for the use case. A test would involve overriding the method to ensure that the API isn't removed. |
@timgraham Here's the use case basically: jazzband/django-oauth-toolkit@d3400ed I am overriding URLValidator because in oauth2, I need something that can take it more types of URIs (such as Scheme validation is done outside the validator as it requires a call to the overridable model.get_allowed_schemes() in order to get the list: URLValidator makes it very hard to override. In EmailValidator, I don't believe |
Right, The proposed change doesn't strike me as a simplification or a refactoring that would be done if not for your use case. Another contributor could just as easily come along and say "Remove unneeded validate_schema() method" and call that a refactoring. |
@timgraham Fair point. In that case, how to proceed with this PR? It feels heavy-handed to make this a public API. |
@timgraham Digging a bit I found a similar ticket: https://code.djangoproject.com/ticket/26424 I think the approach here in this PR is better. What do you think? |
Jerome, could you add a test and refer to #26424 in your commit message? |
Yes certainly. Do you think this ticket closes it? |
Done |
6411bf9
to
ba7ff46
Compare
@jleclanche Working on test failures? |
This allows subclassing URLValidator to do fancier types of validation such as regex matching, etc. Refs. #26424
Didn't even notice. Working on it. |
Closing per ticket. |
This allows subclassing URLValidator to do fancier types of validation
such as regex matching, etc.
Use case: in django-oauth-toolkit, the list of allowed schemes is dynamic. This trivial change allows DOT to subclass URLValidator rather than having to reimplement it entirely.