Improve absolute path detection for cross-platform compatibility

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-12 09:22:26 +00:00
parent 63b71d9945
commit aa5c338086

View file

@ -11,8 +11,13 @@ public static class Url
var buffer = new StringBuilder(); var buffer = new StringBuilder();
var position = 0; var position = 0;
// Check if the path is absolute // Check if the path is absolute (either Unix-style or Windows-style)
var isAbsolute = Path.IsPathRooted(filePath); // Unix: starts with /
// Windows: starts with drive letter followed by colon (e.g., C:)
var isUnixAbsolute = filePath.StartsWith('/') || filePath.StartsWith('\\');
var isWindowsAbsolute =
filePath.Length >= 2 && char.IsLetter(filePath[0]) && filePath[1] == ':';
var isAbsolute = isUnixAbsolute || isWindowsAbsolute;
// For absolute paths, prepend file:// protocol for proper browser handling // For absolute paths, prepend file:// protocol for proper browser handling
if (isAbsolute) if (isAbsolute)
@ -21,7 +26,7 @@ public static class Url
// On Windows, we need to add an extra slash before the drive letter // On Windows, we need to add an extra slash before the drive letter
// e.g., file:///C:/path instead of file://C:/path // e.g., file:///C:/path instead of file://C:/path
if (!filePath.StartsWith('/') && !filePath.StartsWith('\\')) if (isWindowsAbsolute)
{ {
buffer.Append('/'); buffer.Append('/');
} }