Skip to content

fix: trim whitespace in login and registration serializers (#474) - #671

Open
GeethaBurigalla wants to merge 1 commit into
Kuldeeep18:mainfrom
GeethaBurigalla:fix/backend-trim-login-register-474
Open

fix: trim whitespace in login and registration serializers (#474)#671
GeethaBurigalla wants to merge 1 commit into
Kuldeeep18:mainfrom
GeethaBurigalla:fix/backend-trim-login-register-474

Conversation

@GeethaBurigalla

@GeethaBurigalla GeethaBurigalla commented Jul 12, 2026

Copy link
Copy Markdown

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)
  • Password is left untouched in both, matching the same rule CodeRabbit enforced on the frontend PR

Checklist

  • Tested locally
  • No breaking changes to existing tests
  • Follows repo contribution guidelines

Complements #518. Related to #474.

Summary by CodeRabbit

  • Bug Fixes
    • Improved registration and sign-in reliability by automatically removing extra spaces from email addresses, usernames, and names.
    • Prevented accidental duplicate-account issues caused by leading or trailing whitespace in email addresses.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Registration email and name values are trimmed during serializer validation, and login username or email credentials are trimmed before token authentication.

Changes

Authentication input normalization

Layer / File(s) Summary
Normalize registration and login inputs
backend/users/serializers.py, backend/users/jwt.py
Registration validators trim email, first-name, and last-name values; token authentication trims string username or email input before delegating to the parent validator.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • #474 — Addresses whitespace trimming for registration and login inputs through the updated serializer validation paths.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: trimming whitespace in login and registration serializers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
backend/users/jwt.py (1)

6-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid a redundant second trim in token validation.

SimpleJWT creates the configured username field as serializers.CharField, and DRF trims it before validate() 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 win

Avoid duplicating DRF’s built-in whitespace trimming.

EmailField and CharField already trim leading/trailing whitespace before custom validators execute, so these .strip() calls add no behavior here. Keep validate_email for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a33158 and ccb6fc4.

📒 Files selected for processing (2)
  • backend/users/jwt.py
  • backend/users/serializers.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant