Skip to content

Commit 556ab29

Browse files
Merge pull request pmengal#22 from reinaldocoelho/master
Adding fix to email with broke quotes.
2 parents 39fe77d + 4311e1d commit 556ab29

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Class Library/ActiveUp.Net.Common/Parser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,15 +1037,15 @@ public static AddressCollection ParseAddresses(string input)
10371037
/// <returns></returns>
10381038
public static Address ParseAddress(string input)
10391039
{
1040-
input = input.TrimEnd(';');
1040+
input = (input ?? "").Replace("\"", "").TrimEnd(';');
10411041
try
10421042
{
10431043
if (!input.Contains("<"))
10441044
return new Address { Email = RemoveWhiteSpaces(input) };
10451045

10461046
Address address = null;
10471047

1048-
Match displayNameMatch = Regex.Match(input, "(\"?(.+)(\"?(?=\\s?<)|(?=<)))");
1048+
var displayNameMatch = Regex.Match(input, "(\"?(.+)(\"?(?=\\s?<)|(?=<)))");
10491049
if (displayNameMatch.Success)
10501050
address = new Address(input.Replace(displayNameMatch.Value, string.Empty).Trim().Trim(new[] { '<', '>' }), displayNameMatch.Groups[1].Value);
10511051
else
@@ -1054,7 +1054,7 @@ public static Address ParseAddress(string input)
10541054
CleanupAddress(address);
10551055
return address;
10561056
}
1057-
catch
1057+
catch (Exception)
10581058
{
10591059
return new Address { Email = input };
10601060
}

Class Library/ActiveUp.Net.Tests/Common/ParserTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ public void should_parse_address_with_no_closing_quote_after_display_name()
107107
address.Name.ShouldEqual("Display Name only one quote");
108108
}
109109

110+
[Test]
111+
public void should_parse_address_with_invalid_empty_quote()
112+
{
113+
var address = Parser.ParseAddress("\"\" [email protected]\"");
114+
address.Email.ShouldEqual("[email protected]");
115+
address.Name.ShouldEqual("");
116+
}
117+
110118
/// <summary>
111119
/// [discussion:641270] - Created discussion to validate if this test is rigth.
112120
/// </summary>

0 commit comments

Comments
 (0)