From 3b8e518b7cfa293d070cf9332c3f61b60e79f1cb Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Wed, 9 Dec 2020 17:36:05 +0100 Subject: [PATCH] C#: Fix regression in path name sanitization --- Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs b/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs index e212dd4..05d5b96 100644 --- a/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs +++ b/Il2CppInspector.Common/Outputs/CSharpCodeStubs.cs @@ -292,8 +292,8 @@ namespace Il2CppInspector.Outputs var usings = nsRefs.OrderBy(n => (n.StartsWith("System.") || n == "System") ? "0" + n : "1" + n); // Ensure output directory exists and is not a file - var dir = Regex.Replace(Path.GetDirectoryName(outFile), @"[<>:""\|\?\*]", "_"); - if (!string.IsNullOrEmpty(dir)) { + var dir = string.Join("_", Path.GetDirectoryName(outFile).Split(Path.GetInvalidPathChars())); + if (!string.IsNullOrEmpty(dir)) { try { Directory.CreateDirectory(dir); } @@ -304,7 +304,8 @@ namespace Il2CppInspector.Outputs } // Sanitize leafname (might be class name with invalid characters) - var leafname = Regex.Replace(Path.GetFileName(outFile), @"[<>:""\|\?\*]", "_"); + var leafname = string.Join("_", Path.GetFileName(outFile).Split(Path.GetInvalidFileNameChars())); + outFile = Path.Combine(dir, leafname); // Create output file