Validate URLs as URLs in API#293
Conversation
Now it will complain if you don't enter a full URL with protocol, matching the old UI behavior. Without this change it doesn't care and just normalizes whatever you input.
Codecov Report
@@ Coverage Diff @@
## master #293 +/- ##
=======================================
Coverage 77.10% 77.10%
=======================================
Files 99 99
Lines 1878 1878
=======================================
Hits 1448 1448
Misses 430 430
Continue to review full report at Codecov.
|
|
Actually i think this is too strict now (it rejects |
erwa
left a comment
There was a problem hiding this comment.
Looks good. It seems you marked this PR as a "Draft"? I think you have to remove that to merge this.
|
I see this is still in draft -- is this ready for review? |
| guesses = serializers.SerializerMethodField() | ||
| # Have to specify this explicitly for validate_url to run | ||
| url = serializers.CharField() | ||
| url = serializers.URLField() |
There was a problem hiding this comment.
Does this allow an empty url? I seem to recall we discussed at some point we might want to create a puzzle placeholder where the url was left blank (and perhaps filled in later).
I'm actually fine with requiring a scheme prefix, as in practice, we'll be copying and pasting URLs from the browser, and the http/https will automatically be included when copying. But if you want to support more user-friendly inputs like foo.com (which makes testing slightly easier), you could do something like auto-prepend http:// when it's missing. Then you can still use URLValidator. (If the URL really should be https://, one can always edit the URL after the puzzle is created.) Here's a related SO post: https://stackoverflow.com/questions/49983328/cleanest-way-to-allow-empty-scheme-in-django-urlfield |
Now it will complain if you don't enter a full URL with protocol,
matching the old UI behavior. Without this change it doesn't care and
just normalizes whatever you input.