forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathHelper.cs
More file actions
32 lines (30 loc) · 1.3 KB
/
PathHelper.cs
File metadata and controls
32 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
namespace OneScript.StandardLibrary
{
/// <summary>
/// Utility methods for working with file paths
/// </summary>
internal static class PathHelper
{
/// <summary>
/// Strips trailing null characters from a path string.
/// This is needed because Windows WebDAV client can add null characters to the end of paths,
/// which causes ArgumentException in System.IO methods.
/// Only trailing null characters are removed to avoid masking potential security issues
/// with null characters in the middle of paths (e.g., "file.txt\0.exe").
/// </summary>
/// <param name="path">Path that may contain trailing null characters</param>
/// <returns>Path with trailing null characters removed, or null if input was null</returns>
public static string StripNullCharacters(string path)
{
if (path == null)
return null;
return path.TrimEnd('\0');
}
}
}