-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Remove From header validation from System.Net.Http #52794
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -720,8 +720,18 @@ public void From_ReadAndWriteProperty_ValueMatchesPriorSetValue() | |
Assert.False(headers.Contains("From"), | ||
"Header store should not contain a header 'From' after setting it to null."); | ||
|
||
Assert.Throws<FormatException>(() => { headers.From = " "; }); | ||
Assert.Throws<FormatException>(() => { headers.From = "invalid email address"; }); | ||
// values are not validated, so invalid values are accepted | ||
headers.From = " "; | ||
eerhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Assert.Equal(" ", headers.From); | ||
|
||
headers.From = "invalid email address"; | ||
Assert.Equal("invalid email address", headers.From); | ||
|
||
// Null and empty string are equivalent. Setting to empty means remove the From header value (if any). | ||
headers.From = string.Empty; | ||
Assert.Null(headers.From); | ||
Assert.False(headers.Contains("From"), | ||
"Header store should not contain a header 'From' after setting it to string.Empty."); | ||
} | ||
|
||
[Fact] | ||
|
@@ -739,14 +749,15 @@ public void From_UseAddMethod_AddedValueCanBeRetrievedUsingProperty() | |
[Fact] | ||
public void From_UseAddMethodWithInvalidValue_InvalidValueRecognized() | ||
{ | ||
// values are not validated, so invalid values are accepted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this one can be removed, it's calling GetParsedValues which is pointless if we don't have a parser. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, per my comments above about using TokenParser, we should keep this and use it to verify that multiple-valued headers are disallowed. |
||
headers.TryAddWithoutValidation("From", " info@example.com ,"); | ||
Assert.Null(headers.GetParsedValues(KnownHeaders.From.Descriptor)); | ||
Assert.Equal("info@example.com ,", headers.GetParsedValues(KnownHeaders.From.Descriptor)); | ||
Assert.Equal(1, headers.GetValues("From").Count()); | ||
Assert.Equal(" info@example.com ,", headers.GetValues("From").First()); | ||
Assert.Equal("info@example.com ,", headers.GetValues("From").First()); | ||
|
||
headers.Clear(); | ||
headers.TryAddWithoutValidation("From", "info@"); | ||
Assert.Null(headers.GetParsedValues(KnownHeaders.From.Descriptor)); | ||
Assert.Equal("info@", headers.GetParsedValues(KnownHeaders.From.Descriptor)); | ||
Assert.Equal(1, headers.GetValues("From").Count()); | ||
Assert.Equal("info@", headers.GetValues("From").First()); | ||
} | ||
|
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.
Yay :)