Path.GetInvalidPathChars() acts differently in C# interactive vs live code
This commit is contained in:
parent
b2e956e70b
commit
a3d38e082d
@ -86,10 +86,15 @@ namespace FileManager
|
|||||||
{
|
{
|
||||||
ArgumentValidator.EnsureNotNull(path, nameof(path));
|
ArgumentValidator.EnsureNotNull(path, nameof(path));
|
||||||
|
|
||||||
|
var invalidChars = Path.GetInvalidPathChars().Union(new[] {
|
||||||
|
'*', '?',
|
||||||
|
// these are weird. If you run Path.GetInvalidPathChars() in C# interactive, these characters are included.
|
||||||
|
// In live code, Path.GetInvalidPathChars() does not include them
|
||||||
|
'"', '<', '>'
|
||||||
|
}).ToArray();
|
||||||
|
|
||||||
var fixedPath = string
|
var fixedPath = string
|
||||||
.Join(illegalCharacterReplacements ?? "", path.Split(Path.GetInvalidPathChars()))
|
.Join(illegalCharacterReplacements ?? "", path.Split(invalidChars))
|
||||||
.Replace("*", illegalCharacterReplacements)
|
|
||||||
.Replace("?", illegalCharacterReplacements)
|
|
||||||
.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
// replace all colons except within the first 2 chars
|
// replace all colons except within the first 2 chars
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user