-
Notifications
You must be signed in to change notification settings - Fork 29
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 URLs as URLs in API #293
base: main
Are you sure you want to change the base?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
@@ -96,7 +96,7 @@ class PuzzleSerializer(serializers.ModelSerializer): | |||
tags = serializers.SerializerMethodField(required=False) | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.