Skip to content

Commit 421079c

Browse files
committed
Use a custom cross-platform GetInvalidFileNameChars to ensure consistent behavior on Ubuntu and Windows
1 parent c022c91 commit 421079c

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

Source/HttpMultipartParser/FilePart.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public FilePart(string name, string fileName, Stream data, string contentType =
9393
public FilePart(string name, string fileName, Stream data, IDictionary<string, string> additionalProperties, string contentType = DefaultContentType, string contentDisposition = DontentDisposition)
9494
{
9595
Name = name;
96-
FileName = fileName?.Split(Path.GetInvalidFileNameChars()).Last();
96+
FileName = fileName?.Split(GetInvalidFileNameChars()).Last();
9797
Data = data;
9898
ContentType = contentType;
9999
ContentDisposition = contentDisposition;
@@ -136,5 +136,20 @@ public FilePart(string name, string fileName, Stream data, IDictionary<string, s
136136
public IReadOnlyDictionary<string, string> AdditionalProperties { get; private set; }
137137

138138
#endregion
139+
140+
#region Private methods
141+
142+
// This is a cross-platform version of Path.GetInvalidFileNameChars() that returns the same array of characters regadless of the operating system.
143+
// We use this method rather than the built-in Path.GetInvalidFileNameChars() because some unit tests were behaving differently on Ubuntu compared to Windows.
144+
private static char[] GetInvalidFileNameChars() => new char[]
145+
{
146+
'\"', '<', '>', '|', '\0',
147+
(char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10,
148+
(char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20,
149+
(char)21, (char)22, (char)23, (char)24, (char)25, (char)26, (char)27, (char)28, (char)29, (char)30,
150+
(char)31, ':', '*', '?', '\\', '/'
151+
};
152+
153+
#endregion
139154
}
140155
}

0 commit comments

Comments
 (0)