From b80c5b45a3b8d9e5687fecd0562deefa303f9bf3 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Thu, 12 Feb 2026 00:06:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=BE=84bug=201+=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GitCommit.txt | 2 +- System/FileSystem.cs | 70 +++++++++++++++++++++++++++++++++----------- utils/Version.cs | 2 +- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/GitCommit.txt b/GitCommit.txt index 8cf14bc..9f42be1 100644 --- a/GitCommit.txt +++ b/GitCommit.txt @@ -1 +1 @@ -03b136f \ No newline at end of file +b36e3ba \ No newline at end of file diff --git a/System/FileSystem.cs b/System/FileSystem.cs index 025a2bb..0f156c7 100644 --- a/System/FileSystem.cs +++ b/System/FileSystem.cs @@ -358,15 +358,22 @@ namespace CMLeonOS public string GetFullPath(string path) { + if (string.IsNullOrEmpty(path)) + { + return currentDirectory; + } + if (path.StartsWith(@"0:\")) { return path; } - else if (path == ".") + + if (path == ".") { return currentDirectory; } - else if (path == "..") + + if (path == "..") { if (currentDirectory == @"0:\") { @@ -385,9 +392,15 @@ namespace CMLeonOS } } } - else if (path.StartsWith("../") || path.StartsWith("..\\")) + + if (path.StartsWith("../") || path.StartsWith("..\\")) { - // 支持多层..操作 + if (currentDirectory == @"0:\") + { + Console.WriteLine("Error: Cannot go above root directory"); + return currentDirectory; + } + int level = 0; string tempPath = path; while (tempPath.StartsWith("../") || tempPath.StartsWith("..\\")) @@ -401,9 +414,14 @@ namespace CMLeonOS { tempPath = tempPath.Substring(3); } + + if (level > 10) + { + Console.WriteLine("Error: Too many parent directory references"); + return currentDirectory; + } } - // 向上移动level级 string resultPath = currentDirectory; for (int i = 0; i < level; i++) { @@ -419,12 +437,11 @@ namespace CMLeonOS } return resultPath; } - else if (path.StartsWith("dir") || path.StartsWith("DIR")) + + if (path.StartsWith("dir") || path.StartsWith("DIR")) { - // 支持cd dir1/dir2/dir3等格式 string dirName = path; - // 提取数字部分 string numberPart = ""; for (int i = 3; i < path.Length; i++) { @@ -438,7 +455,6 @@ namespace CMLeonOS } } - // 构建完整路径 if (currentDirectory == @"0:\") { return $@"0:\{dirName}"; @@ -448,16 +464,36 @@ namespace CMLeonOS return $@"{currentDirectory}\{dirName}"; } } + + string normalizedPath = path; + + if (normalizedPath.StartsWith("/")) + { + normalizedPath = normalizedPath.Substring(1); + } + + if (normalizedPath.StartsWith("\\")) + { + normalizedPath = normalizedPath.Substring(1); + } + + if (normalizedPath.EndsWith("/")) + { + normalizedPath = normalizedPath.Substring(0, normalizedPath.Length - 1); + } + + if (normalizedPath.EndsWith("\\")) + { + normalizedPath = normalizedPath.Substring(0, normalizedPath.Length - 1); + } + + if (currentDirectory == @"0:\") + { + return $@"0:\{normalizedPath}"; + } else { - if (currentDirectory == @"0:\") - { - return $@"0:\{path}"; - } - else - { - return $@"{currentDirectory}\{path}"; - } + return $@"{currentDirectory}\{normalizedPath}"; } } } diff --git a/utils/Version.cs b/utils/Version.cs index 549206d..8114116 100644 --- a/utils/Version.cs +++ b/utils/Version.cs @@ -7,7 +7,7 @@ namespace CMLeonOS public static string Major = "1"; public static string Minor = "0"; public static string Patch = "0"; - public static string VersionType = "PreRelease"; + public static string VersionType = "PreRelease 2"; public static string GitCommit = "unknown"; public static string FullVersion