Skip to content

Commit 866c2aa

Browse files
CopilotJustinGrote
andauthored
Harden ToString path handling for null and separators
Agent-Logs-Url: https://github.com/PowerShell/PowerShellEditorServices/sessions/6285ab7f-3d36-4174-84cd-57dcebf32386 Co-authored-by: JustinGrote <15258962+JustinGrote@users.noreply.github.com>
1 parent 8afd2a5 commit 866c2aa

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/PowerShellEditorServices/Extensions/EditorWorkspace.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ internal EditorWorkspaceDocument(EditorWorkspace workspace, string path, bool sa
3333
/// <returns>The display name of this document.</returns>
3434
public override string ToString()
3535
{
36-
int fileNameStartIndex = System.Math.Max(Path.LastIndexOf('\\'), Path.LastIndexOf('/')) + 1;
37-
string fileName = Path.Substring(fileNameStartIndex);
36+
string documentPath = Path ?? string.Empty;
37+
// Handle Windows and POSIX separators consistently across platforms.
38+
int fileNameStartIndex = System.Math.Max(documentPath.LastIndexOf('\\'), documentPath.LastIndexOf('/')) + 1;
39+
string fileName = documentPath.Substring(fileNameStartIndex);
3840
return Saved ? fileName : fileName + " [Unsaved]";
3941
}
4042

0 commit comments

Comments
 (0)