Opened 3 years ago

Closed 3 years ago

#32954 closed Cleanup/optimization (wontfix)

Improve error message with URLValidator and schemes

Reported by: tomdjango Owned by: nobody
Component: Uncategorized Version: 3.2
Severity: Normal Keywords: error message
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you limit the schemes for a URL to a subset of legal values with URLValidator, like this:

url = models.URLField(max_length=200, validators=[URLValidator(["http","https"])])

And then enter a value URL starting with "ftp://", the error message given is

Enter a valid URL.

The URL is valid, so this does not give the user useful information for fixing the problem. Something like

URL must begin with one of [http, https]

would be more helpful.

Change History (1)

comment:1 by Carlton Gibson, 3 years ago

Resolution: wontfix
Status: newclosed

I think using `error_messages` is the way forward here.

I don't think we can change the default — too many projects will depend on that — and I'd guess folks would object that we were leaking unwanted info if we added extra context here.

What's a Valid URL for the application depends on the validators in play. Lots and lots and lots of "Valid URLs" (from an RFC perspective) are already excluded by URLValidator.schemes' default value. "Enter a valid URL." already takes this into account.

I hope that makes sense.

Note: See TracTickets for help on using tickets.
Back to Top