-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fixed issue 36752 mail address display name #37874
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
Conversation
|
Tagging subscribers to this area: @dotnet/ncl |
|
You should add unit tests with reasonable coverage for the change @jaymin93 |
|
I had hard time to write unit test on multiple machines it was not working apart from it I gave a try from other computer. I write some test for it but I can see there are existing code for mailadress parser.cs which does not allows double quotes and throwing the exception for the test so I need to edit those as well? |
|
By looking at that code it seems it means to not allow the quotes |
|
You should perkas get use cases from @J0nKn1ght . The linked issue was about printing so I would assume there is valid case with double quotes not requiting any production changes. |
for the issue #36752
|
i seen your comment and i tried to run the test from cli , but shows the same as one vs but anyway i tried to build a test with different computer and ran on that machine wrote same code and committed issue still persist but that will not stop me from making pr :) i added one test by reviewing the existing one , please let me know in case i need to do something else as well. thanks for all help |
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this was viewed as part of serialization, I think should add more tests to make sure it actually works. (see the comment form @karelz)
| Assert.Equal(string.Format("\"{0}\" <{1}>", DisplayNameWithUnicode, Address), _mailAddress.ToString()); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. extra line
| public void MailAddress_WithDoubleQuotesDisplayAndMailAddress_ToStringShouldReturnDisplayNameEscapeSequenceAndAddressInAngleBrackets() | ||
| { | ||
| MailAddress _mailAddress = new MailAddress(Address, DisplayNameWithDoubleQuotes); | ||
| Assert.Equal(DisplayNameWithDoubleQuotes,_mailAddress.DisplayName ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're talking about the whitespaces, there's one missing after ',' and one extra before ')'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok @ManickaP i will add that and @wfurt can you help me with similar kind of test cases exist (path or source link ) so i can check out that and add necessary test for it , as well i seen comment of karelz but not quite sure that i understood it well if you can elaborate a bit that will help. thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManickaP can you help me with similar kind of test cases exist (path or source link ) so i can check out that and add necessary test for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The serialization was meant to be "store into string" (as in opposite to parsing). No serialization attribute is necessary.
We should add couple of more corner case tests (@ManickaP has couple of more).
We should migrate these tests into MemberData -- it will be useful and simpler, given we have quite a few test cases now).
We could consider using the test as well for parsing -- parse string, then call .ToString() (check it is same) ... this is nice to have for this PR, not blocking.
| [Fact] | ||
| public void MailAddress_WithDoubleQuotesDisplayAndMailAddress_ToStringShouldReturnDisplayNameEscapeSequenceAndAddressInAngleBrackets() | ||
| { | ||
| MailAddress _mailAddress = new MailAddress(Address, DisplayNameWithDoubleQuotes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit remove leading '_' (even though the previous test has it, it should be fixed later as well -- in a separate PR ideally).
@ManickaP has even better idea to simplify tests in this file, again that should be separate issue / PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New issue: #39625
| private const string Address = "test@example.com"; | ||
| private const string DisplayNameWithUnicode = "DisplayNameWith\u00C9\u00C0\u0106\u0100\u0109\u0105\u00E4Unicode"; | ||
| private const string DisplayNameWithNoUnicode = "testDisplayName"; | ||
| private const string DisplayNameWithDoubleQuotes = "test\"Display\"Name"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test cases:
- ""John Doe"" ... double quotes at the end
- "Hello "world hello" world" ... double quotes in the middle around spaces - typical use case
- "Hello "world" ... just one double quote (technically kind of incorrect value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More test cases:
- "Hello ""world" ... quotes next to each other
- """" ... only quotes (I don't know if it won't be rejected by
MailAddressctor) - """ ... single quote, nothing else
- "Hello \"world hello\" world" ... escaped backslash before quotes (what's the behavior for this right now?)
|
BTW: What if |
|
@ManickaP @karelz i had issue running tests locally , it never worked for me to run test locally , i know this is not ideal way but i tried to commit it and wanted to run as part of ci/cd pipeline . it never worked on my 2 personal computer , it works on my work machine although changing to theory from fact and adding member data was not allowing to run on that machine as well so i don't have any other way to test . so could you please suggest. test output are as below Log level is set to Informational (Default). |
|
Let's try to troubleshoot your local environment first. It will be IMO more efficient. |
|
yes sure , I will create a new issue. |
|
@ManickaP yes i was doing steps given in the link , to make sure i also executed the steps again but issue is same i think Log level is set to Informational (Default). should i open issue ? |
|
@ManickaP @karelz on my surface go i was able to execute the tests , but for the method with theory and member data i am getting below exception which is similar to the one i am getting on my work machine which was running test earlier , still my one machine with vs 2019 preview community latest preview is not able to run it , but since i am able to run it on one machine it's ok for me so for below issue do you have any suggestion? [xUnit.net 00:00:31.24] System.NotSupportedException : Specified method is not supported. Log level is set to Informational (Default). |
|
It's not |
|
@ManickaP thanks i have changed it to the inline data and it worked as expected , as you and karelz suggested i added suggested test in inline data , the only issue i see right now is when the quotes are at beginning and ending of the string it fail the test since the below link there is code to remove the quotes from start and end so i am not sure that needs to change as the comment suggest quotes will be added later but i do not see later they are added back from constructor so please suggest appropriate action.
|
|
|
@karelz can you please help me with your valuable opinion what should i do here since the if condition is for checking first and last quotes and only and current behavior of .net core 3.1(prod libs) that it is removing the quotes and doesn't added back if string has quotes in start and end for e.g ""John Doe"" will return "John Doe" test@example.com and that's where my tests are also failing, and i am also not aware what is exact use case for removing start and end quote in current code so your opinion will help me here. Thanks |
|
The current behavior is correct, leading and trailing |
|
@ManickaP tried to implement with split tests as you suggested please review and share your views |
I'll give it another look, though probably after weekend. |
| private const string DisplayNameWithUnicode = "DisplayNameWith\u00C9\u00C0\u0106\u0100\u0109\u0105\u00E4Unicode"; | ||
| private const string DisplayNameWithNoUnicode = "testDisplayName"; | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: extra empty line
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Outdated
Show resolved
Hide resolved
| if (displayNameWithDoubleQuotesInBeginningAndInEnding.Length >= 2 && displayNameWithDoubleQuotesInBeginningAndInEnding[0] == '\"' && displayNameWithDoubleQuotesInBeginningAndInEnding[^1] == '\"') | ||
| { | ||
|
|
||
| displayNameWithDoubleQuotesInBeginningAndInEnding = displayNameWithDoubleQuotesInBeginningAndInEnding.Substring(1, displayNameWithDoubleQuotesInBeginningAndInEnding.Length - 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not testing what we want though. You're stripping the quotes before you pass it to the MailAddress ctor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then what is suggested action here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the substring after the call of the MailAddress ctor.
| [InlineData(Address, "\"\"")] | ||
| public void MailAddress_WithDoubleQuotesInBeginningAndInEndingDisplayAndMailAddress_ToStringShouldReturnDisplayNameEscapeSequenceAndAddressInAngleBrackets(string address, string displayNameWithDoubleQuotesInBeginningAndInEnding) | ||
| { | ||
| if (displayNameWithDoubleQuotesInBeginningAndInEnding.Length >= 2 && displayNameWithDoubleQuotesInBeginningAndInEnding[0] == '\"' && displayNameWithDoubleQuotesInBeginningAndInEnding[^1] == '\"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the test here, the test is only for such data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you told me to split the test cases so i created separate test case for kind of test what would be recommended action here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the comment, I mean the if since you already know it starts and ends with '"' by the definition of the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i had internet issues and i was not able to review your comment properly , but now i have applied the all suggestion you told , please review it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManickaP any update on review or merge status for pr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, Karel have to approve as well though. Thanks for the patience and your contribution 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManickaP @karelz @wfurt i really appreciate all your feedback and valuable opinion and kind help, since I was new to github it self this is the first contribution I did in lifetime so I was kind of newbie but all your guidance and help made worth of contributing and really looking forward to do more love 😍 .net
…AddressDisplayNameTest.cs Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
…AddressDisplayNameTest.cs Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the contribution!
|
@karelz since you requested change, you have to approve as well, otherwise the PR's blocked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on it @jaymin93! Just few minor changes and one question left ...
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Show resolved
Hide resolved
src/libraries/System.Net.Mail/tests/Unit/MailAddressTests/MailAddressDisplayNameTest.cs
Outdated
Show resolved
Hide resolved
…AddressDisplayNameTest.cs updated address in small case Co-authored-by: Karel Zikmund <karelz@microsoft.com>
…AddressDisplayNameTest.cs updated address in small a Co-authored-by: Karel Zikmund <karelz@microsoft.com>
…AddressDisplayNameTest.cs updated address in small a Co-authored-by: Karel Zikmund <karelz@microsoft.com>
|
@ManickaP you told i need to merge into master and i am done with @karelz 's requested changes ,but i am not sure if i can merge (i think i must not have necessary rights to do same and i can not see any option do it but i can be wrong as well since i am new to github ) but anything from my end is required to do so i will do it so please suggest me what action i should take . Thanks |
|
You're blocked by @karelz, he needs to approve first, than you can merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @jaymin93. Sorry for the delay 😔
|
@ManickaP it shows "Only those with write access to this repository can merge pull requests." that button is not present in my case |


fixed issue 36752 mail address double quotes in DisplayName
link to issue
fixes #36752
there are few issues i am facing with the unit test. if anything needs to be added please bring in to my attention. since this is my first pr i don't know much about process.