Skip to content

Commit 8c9206e

Browse files
Copilotnixel2007
andauthored
Use TrimEnd('\0') instead of Replace("\0", "") for null character stripping (EvilBeaver#1650)
* Initial plan * Initial plan for fixing null character handling Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> * Fix: Use TrimEnd('\0') instead of Replace("\0", "") for safer null char handling Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> * Complete PR with all checks passed Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> * Remove accidentally committed nuget.exe Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> * Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> * Remove opm.ospx - should not be in repository Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
1 parent 5948bb5 commit 8c9206e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/OneScript.StandardLibrary/PathHelper.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ namespace OneScript.StandardLibrary
1313
internal static class PathHelper
1414
{
1515
/// <summary>
16-
/// Strips null characters from a path string.
17-
/// This is needed because Windows WebDAV client can add null characters to paths,
16+
/// Strips trailing null characters from a path string.
17+
/// This is needed because Windows WebDAV client can add null characters to the end of paths,
1818
/// which causes ArgumentException in System.IO methods.
19+
/// Only trailing null characters are removed to avoid masking potential security issues
20+
/// with null characters in the middle of paths (e.g., "file.txt\0.exe").
1921
/// </summary>
20-
/// <param name="path">Path that may contain null characters</param>
21-
/// <returns>Path with null characters removed, or null if input was null</returns>
22+
/// <param name="path">Path that may contain trailing null characters</param>
23+
/// <returns>Path with trailing null characters removed, or null if input was null</returns>
2224
public static string StripNullCharacters(string path)
2325
{
2426
if (path == null)
2527
return null;
2628

27-
return path.Replace("\0", "");
29+
return path.TrimEnd('\0');
2830
}
2931
}
3032
}

0 commit comments

Comments
 (0)