Skip to content
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

[PM-7842] Fix validation of IDN emails #4036

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Utilities/StrictEmailAddressAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override bool IsValid(object value)
try
{
var parsedEmailAddress = MailboxAddress.Parse(emailAddress).Address;
if (parsedEmailAddress != emailAddress)
if (string.IsNullOrEmpty(parsedEmailAddress))
{
return false;
}
Expand Down
15 changes: 9 additions & 6 deletions test/Core.Test/Utilities/StrictEmailAddressAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ namespace Bit.Core.Test.Utilities;
public class StrictEmailAttributeTests
{
[Theory]
[InlineData("[email protected]")] // regular email address
[InlineData("[email protected]")] // subdomain
[InlineData("[email protected]")] // alias
[InlineData("[email protected]")] // period in local-part
[InlineData("hello@wörldé.com")] // unicode domain
[InlineData("[email protected]ömé")] // unicode top-level domain
[InlineData("[email protected]")] // regular email address
[InlineData("[email protected]")] // subdomain
[InlineData("[email protected]")] // alias
[InlineData("[email protected]")] // period in local-part
[InlineData("hello@wörldé.com")] // unicode domain
[InlineData("[email protected]")] // punycoded domain
[InlineData("[email protected]ömé")] // unicode top-level domain
[InlineData("[email protected]")] // punycoded top-level domain
public void IsValid_ReturnsTrueWhenValid(string email)
{
var sut = new StrictEmailAddressAttribute();
Expand Down Expand Up @@ -47,6 +49,7 @@ public void IsValid_ReturnsTrueWhenValid(string email)
[InlineData("[email protected]")] // domain ending in hyphen
[InlineData("hellö@world.com")] // unicode at end of local-part
[InlineData("hé[email protected]")] // unicode in middle of local-part
[InlineData("hé[email protected]")] // invalid punycode domain
public void IsValid_ReturnsFalseWhenInvalid(string email)
{
var sut = new StrictEmailAddressAttribute();
Expand Down
Loading