Skip to content

Fix/email validation regex - #1026

Open
cubegao wants to merge 2 commits into
flutter:mainfrom
cubegao:fix/email-validation-regex
Open

Fix/email validation regex#1026
cubegao wants to merge 2 commits into
flutter:mainfrom
cubegao:fix/email-validation-regex

Conversation

@cubegao

@cubegao cubegao commented Aug 20, 2026

Copy link
Copy Markdown

Fix the email validation function by correcting the regex escape pattern.

The previous implementation used an escaped $ in a raw string, which caused the regex to match a literal $ character instead of the end-of-string anchor.

Update the regex pattern to properly validate email formats.

Description

This PR fixes an issue in the email validation function where the regular expression pattern did not correctly handle the end-of-string anchor.

The previous implementation incorrectly escaped the $ character inside a Dart raw string. As a result, the regex engine treated it as a literal character instead of the end-of-string matcher, causing valid email addresses to fail validation.

This change updates the regex pattern to use the correct $ anchor and ensures email validation behaves as expected.

Related Issues

N/A

Testing

  • Verified that valid email addresses are correctly accepted.
  • Verified that invalid email formats are rejected.

Pre-launch Checklist

  • The code changes have been tested.
  • The updated validation logic works as expected.
  • Documentation updates are not required.

Fix the email validation function by correcting the regex escape pattern.

The previous implementation used an escaped `$` in a raw string, which caused the regex to match a literal `$` character instead of the end-of-string anchor.

Update the regex pattern to properly validate email formats.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request corrects a bug in the email validation regular expression within EmailFunction by fixing an incorrectly escaped end anchor, and introduces comprehensive unit tests to verify its behavior. The reviewer recommends optimizing performance by declaring the RegExp as a static final field to prevent recompiling it on every function invocation.

final Object? value = args['value'];
if (value is! String) return false;
final emailRegex = RegExp(r'^[^@]+@[^@]+\.[^@]+\$');
final emailRegex = RegExp(r'^[^@]+@[^@]+\.[^@]+$');

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.

medium

Instantiating a RegExp on every invocation of executeSync is inefficient because compiling a regular expression is a relatively expensive operation. Since EmailFunction has a const constructor, you cannot declare a non-static instance field. Instead, consider declaring the RegExp as a static final field inside the EmailFunction class (or as a private top-level variable in the file) to compile it only once.

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