fix: trim whitespace in login and registration serializers (#474) - #671
fix: trim whitespace in login and registration serializers (#474)#671GeethaBurigalla wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughRegistration email and name values are trimmed during serializer validation, and login username or email credentials are trimmed before token authentication. ChangesAuthentication input normalization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/users/jwt.py (1)
6-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid a redundant second trim in token validation.
SimpleJWT creates the configured username field as
serializers.CharField, and DRF trims it beforevalidate()runs. This override therefore adds no behavior with the current dependencies; remove it unless you intentionally want an explicit defensive contract and accompanying regression test. (raw.githubusercontent.com)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/users/jwt.py` around lines 6 - 11, Remove the validate override and its redundant username-field trimming from the token serializer, allowing the inherited validation to handle the configured username field. Preserve the existing password behavior and other serializer functionality.backend/users/serializers.py (1)
23-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid duplicating DRF’s built-in whitespace trimming.
EmailFieldandCharFieldalready trim leading/trailing whitespace before custom validators execute, so these.strip()calls add no behavior here. Keepvalidate_emailfor uniqueness checking, but consider removing the redundant normalization or explicitly configuring the fields if this contract must remain visible. (django-rest-framework.org)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/users/serializers.py` around lines 23 - 34, Remove the redundant whitespace stripping from validate_email, validate_first_name, and validate_last_name, relying on DRF field trimming while preserving email uniqueness validation and existing empty-value handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/users/jwt.py`:
- Around line 6-11: Remove the validate override and its redundant
username-field trimming from the token serializer, allowing the inherited
validation to handle the configured username field. Preserve the existing
password behavior and other serializer functionality.
In `@backend/users/serializers.py`:
- Around line 23-34: Remove the redundant whitespace stripping from
validate_email, validate_first_name, and validate_last_name, relying on DRF
field trimming while preserving email uniqueness validation and existing
empty-value handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 6ea03123-cba3-4731-8b93-c597725a313a
📒 Files selected for processing (2)
backend/users/jwt.pybackend/users/serializers.py
Description
PR #518 covers the frontend half of #474 (trimming login/register inputs before submission), but CodeRabbit's own review on that PR flagged that the backend serializer trimming requested by the issue was still missing.
This PR adds that missing half. No frontend files touched, no overlap with #518.
Changes
CustomTokenObtainSerializer.validate: trims email before authentication (login)RegisterSerializer: trims email, first_name, and last_name (registration)Checklist
Complements #518. Related to #474.
Summary by CodeRabbit