From ca44dd4e23bcf46da187f9ef9aabfe40cdfa04e5 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH] Ensure replacement only at start of string --- core/commands/slash/share.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 608459669..72ab08105 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -38,25 +38,23 @@ const ShareSlashCommand: SlashCommand = { if (!outputDir) { outputDir = await ide.getContinueDir(); } + if (outputDir.startsWith("~")) { - outputDir = outputDir.replace(/~/, homedir); - } - //TODO: error handling, create path if it doesn't exist? - - const workspaceDirs = await ide.getWorkspaceDirs(); - - // Although the most common situation is to have one directory open in a - // workspace it's also possible to have just a file open without an - // associated directory or to use multi-root workspaces in which multiple - // folders are included. We default to using the first item in the list, if - // it exists. - const workspaceDirectory = workspaceDirs?.[0] || ""; - if ( + outputDir = outputDir.replace(/^~/, homedir); + } else if ( outputDir.startsWith("./") || outputDir.startsWith(`.\\`) || outputDir === "." ) { - outputDir = outputDir.replace(".", workspaceDirectory); + const workspaceDirs = await ide.getWorkspaceDirs(); + // Although the most common situation is to have one directory open in a + // workspace it's also possible to have just a file open without an + // associated directory or to use multi-root workspaces in which multiple + // folders are included. We default to using the first item in the list, if + // it exists. + const workspaceDirectory = workspaceDirs?.[0] || ""; + outputDir = outputDir.replace(/^./, workspaceDirectory); + } } const dtString = asBasicISOString(getOffsetDatetime(now));