diff --git a/src/Microsoft.Net.Http.Headers/ContentDispositionHeaderValue.cs b/src/Microsoft.Net.Http.Headers/ContentDispositionHeaderValue.cs index ff9faf066b..b9292ac1a8 100644 --- a/src/Microsoft.Net.Http.Headers/ContentDispositionHeaderValue.cs +++ b/src/Microsoft.Net.Http.Headers/ContentDispositionHeaderValue.cs @@ -73,6 +73,7 @@ namespace Microsoft.Net.Http.Headers set { SetName(NameString, value); } } + public StringSegment FileName { get { return GetName(FileNameString); } @@ -337,7 +338,7 @@ namespace Microsoft.Net.Http.Headers // Gets a parameter of the given name and attempts to decode it if necessary. // Returns null if the parameter is not present or the raw value if the encoding is incorrect. - private string GetName(string parameter) + private StringSegment GetName(string parameter) { var nameParameter = NameValueHeaderValue.Find(_parameters, parameter); if (nameParameter != null) @@ -359,7 +360,7 @@ namespace Microsoft.Net.Http.Headers return result; } // May not have been encoded - return nameParameter.Value.ToString(); + return HeaderUtilities.RemoveQuotes(nameParameter.Value); } return null; } diff --git a/test/Microsoft.Net.Http.Headers.Tests/ContentDispositionHeaderValueTest.cs b/test/Microsoft.Net.Http.Headers.Tests/ContentDispositionHeaderValueTest.cs index 17f9623347..ad1f7fce1f 100644 --- a/test/Microsoft.Net.Http.Headers.Tests/ContentDispositionHeaderValueTest.cs +++ b/test/Microsoft.Net.Http.Headers.Tests/ContentDispositionHeaderValueTest.cs @@ -152,7 +152,7 @@ namespace Microsoft.Net.Http.Headers Assert.Equal(1, contentDisposition.Parameters.Count); Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); - Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.FileName); + Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=", contentDisposition.FileName); contentDisposition.FileName = "new_name"; Assert.Equal("new_name", contentDisposition.FileName); @@ -560,6 +560,19 @@ namespace Microsoft.Net.Http.Headers Assert.Throws(() => ContentDispositionHeaderValue.Parse(input)); } + [Fact] + public void HeaderNamesWithQuotes_ExpectNamesToNotHaveQuotes() + { + var contentDispositionLine = "form-data; name =\"dotnet\"; filename=\"example.png\""; + var expectedName = "dotnet"; + var expectedFileName = "example.png"; + + var result = ContentDispositionHeaderValue.Parse(contentDispositionLine); + + Assert.Equal(expectedName, result.Name); + Assert.Equal(expectedFileName, result.FileName); + } + public class ContentDispositionValue { public ContentDispositionValue(string value, string description, bool valid)