Removes quotes from names in ContentDispositionHeaderValue
This commit is contained in:
parent
78768e38c8
commit
a8270a4901
|
|
@ -73,6 +73,7 @@ namespace Microsoft.Net.Http.Headers
|
||||||
set { SetName(NameString, value); }
|
set { SetName(NameString, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public StringSegment FileName
|
public StringSegment FileName
|
||||||
{
|
{
|
||||||
get { return GetName(FileNameString); }
|
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.
|
// 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.
|
// 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);
|
var nameParameter = NameValueHeaderValue.Find(_parameters, parameter);
|
||||||
if (nameParameter != null)
|
if (nameParameter != null)
|
||||||
|
|
@ -359,7 +360,7 @@ namespace Microsoft.Net.Http.Headers
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// May not have been encoded
|
// May not have been encoded
|
||||||
return nameParameter.Value.ToString();
|
return HeaderUtilities.RemoveQuotes(nameParameter.Value);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ namespace Microsoft.Net.Http.Headers
|
||||||
Assert.Equal(1, contentDisposition.Parameters.Count);
|
Assert.Equal(1, contentDisposition.Parameters.Count);
|
||||||
Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name);
|
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.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";
|
contentDisposition.FileName = "new_name";
|
||||||
Assert.Equal("new_name", contentDisposition.FileName);
|
Assert.Equal("new_name", contentDisposition.FileName);
|
||||||
|
|
@ -560,6 +560,19 @@ namespace Microsoft.Net.Http.Headers
|
||||||
Assert.Throws<FormatException>(() => ContentDispositionHeaderValue.Parse(input));
|
Assert.Throws<FormatException>(() => 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 class ContentDispositionValue
|
||||||
{
|
{
|
||||||
public ContentDispositionValue(string value, string description, bool valid)
|
public ContentDispositionValue(string value, string description, bool valid)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue