[PR #5440] test(mongodb): add tests for special character handling #6011

Open
opened 2026-03-13 12:44:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5440
Author: @ahmed-abdat
Created: 10/20/2025
Status: 🔄 Open

Base: canaryHead: fix/mongodb-special-characters-5409


📝 Commits (3)

  • 2ab8dda test(mongodb): add tests for special character handling
  • 759c039 Merge canary into fix/mongodb-special-characters-5409
  • da6197f test: move special character tests to shared auth-flow suite

📊 Changes

2 files changed (+167 additions, -4 deletions)

View changed files

📝 packages/better-auth/src/adapters/tests/auth-flow.ts (+165 -0)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+2 -4)

📄 Description

Fixes #5409

Problem

The MongoDB adapter list-users query was failing when searching for emails with special characters like plus signs (user+tag@gmail.com). While the fix (escapeForMongoRegex function) was already implemented, there was no test coverage to verify it works correctly.

Solution

Added comprehensive test suite covering all regex special characters that could cause issues in MongoDB queries.

Tests

  • Plus signs in email addresses (Gmail aliases: test+alias@example.com)
  • Dots in email addresses (user.name@example.com)
  • Asterisks, question marks, and brackets in names
  • Backslashes in names
  • Tests for all three operators: contains, starts_with, ends_with
  • All tests pass with the existing escapeForMongoRegex implementation

Summary by cubic

Added tests to ensure user search across all adapters correctly escapes regex special characters, preventing failures for addresses like user+tag@gmail.com. Fixes #5409 and covers +, ., *, ?, [], and \ for contains, starts_with, and ends_with.

Written for commit da6197f621. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5440 **Author:** [@ahmed-abdat](https://github.com/ahmed-abdat) **Created:** 10/20/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `fix/mongodb-special-characters-5409` --- ### 📝 Commits (3) - [`2ab8dda`](https://github.com/better-auth/better-auth/commit/2ab8ddae0e82a8d229a6ca529a4b4b01023affde) test(mongodb): add tests for special character handling - [`759c039`](https://github.com/better-auth/better-auth/commit/759c039f7ce6fb5d0dfbeebe591ca8149dc9ad5e) Merge canary into fix/mongodb-special-characters-5409 - [`da6197f`](https://github.com/better-auth/better-auth/commit/da6197f6215c4dec90d90f1969def438dd9a1543) test: move special character tests to shared auth-flow suite ### 📊 Changes **2 files changed** (+167 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/tests/auth-flow.ts` (+165 -0) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+2 -4) </details> ### 📄 Description Fixes #5409 ### Problem The MongoDB adapter list-users query was failing when searching for emails with special characters like plus signs (`user+tag@gmail.com`). While the fix (`escapeForMongoRegex` function) was already implemented, there was no test coverage to verify it works correctly. ### Solution Added comprehensive test suite covering all regex special characters that could cause issues in MongoDB queries. ### Tests - [x] Plus signs in email addresses (Gmail aliases: `test+alias@example.com`) - [x] Dots in email addresses (`user.name@example.com`) - [x] Asterisks, question marks, and brackets in names - [x] Backslashes in names - [x] Tests for all three operators: `contains`, `starts_with`, `ends_with` - [x] All tests pass with the existing `escapeForMongoRegex` implementation <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added tests to ensure user search across all adapters correctly escapes regex special characters, preventing failures for addresses like user+tag@gmail.com. Fixes #5409 and covers +, ., *, ?, [], and \ for contains, starts_with, and ends_with. <sup>Written for commit da6197f6215c4dec90d90f1969def438dd9a1543. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:44:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6011