Skip to content

Commit ad28c88

Browse files
committed
Avoid mangling paths given to ExecuteScriptWithArgsAsync
Some extant code was using PowerShell to get the current working directory and then was hardcoded to prepend that to the given path, in order to make an "absolute path." This was buggy, but also seemed unnecessary as the current working directory should be fine, and so hopefully relative paths work without this code. Absolute paths already work without it because of the `File.Exists` logic; the potential bug is if that operates in a different working directory than PowerShell.
1 parent 095c031 commit ad28c88

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,28 +1040,6 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
10401040

10411041
if (arguments != null)
10421042
{
1043-
// Need to determine If the script string is a path to a script file.
1044-
string scriptAbsPath = string.Empty;
1045-
try
1046-
{
1047-
// Assume we can only debug scripts from the FileSystem provider
1048-
string workingDir = (await ExecuteCommandAsync<PathInfo>(
1049-
new PSCommand()
1050-
.AddCommand("Microsoft.PowerShell.Management\\Get-Location")
1051-
.AddParameter("PSProvider", "FileSystem"),
1052-
sendOutputToHost: false,
1053-
sendErrorToHost: false).ConfigureAwait(false))
1054-
.FirstOrDefault()
1055-
.ProviderPath;
1056-
1057-
workingDir = workingDir.TrimEnd(Path.DirectorySeparatorChar);
1058-
scriptAbsPath = workingDir + Path.DirectorySeparatorChar + script;
1059-
}
1060-
catch (System.Management.Automation.DriveNotFoundException e)
1061-
{
1062-
this.logger.LogHandledException("Could not determine current filesystem location", e);
1063-
}
1064-
10651043
var strBld = new StringBuilder();
10661044

10671045
// The script parameter can refer to either a "script path" or a "command name". If it is a
@@ -1071,7 +1049,7 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
10711049
// If the provided path is already quoted, then File.Exists will not find it.
10721050
// This keeps us from quoting an already quoted path.
10731051
// Related to issue #123.
1074-
if (File.Exists(script) || File.Exists(scriptAbsPath))
1052+
if (File.Exists(script))
10751053
{
10761054
// Dot-source the launched script path and single quote the path in case it includes
10771055
strBld.Append(". ").Append(QuoteEscapeString(script));

0 commit comments

Comments
 (0)