Skip to content

Commit ce20e65

Browse files
author
Robert Holt
committed
Fix remaining uses of glob to wildcard
1 parent 2d6a37c commit ce20e65

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ protected async Task HandleLaunchRequest(
259259
// the path exists and is a directory.
260260
if (!string.IsNullOrEmpty(workingDir))
261261
{
262-
workingDir = PowerShellContext.UnescapeGlobEscapedPath(workingDir);
262+
workingDir = PowerShellContext.UnescapeWildcardEscapedPath(workingDir);
263263
try
264264
{
265265
if ((File.GetAttributes(workingDir) & FileAttributes.Directory) != FileAttributes.Directory)

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpoints(
178178
// Fix for issue #123 - file paths that contain wildcard chars [ and ] need to
179179
// quoted and have those wildcard chars escaped.
180180
string escapedScriptPath =
181-
PowerShellContext.GlobEscapePath(scriptPath);
181+
PowerShellContext.WildcardEscapePath(scriptPath);
182182

183183
if (dscBreakpoints == null || !dscBreakpoints.IsDscResourcePath(escapedScriptPath))
184184
{

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,8 +1129,8 @@ public async Task SetWorkingDirectory(string path, bool isPathAlreadyEscaped)
11291129
/// <returns>An escaped version of the path that can be embedded in PowerShell script.</returns>
11301130
internal static string FullyPowerShellEscapePath(string path)
11311131
{
1132-
string globEscapedPath = WildcardEscapePath(path);
1133-
return QuoteEscapeString(globEscapedPath);
1132+
string wildcardEscapedPath = WildcardEscapePath(path);
1133+
return QuoteEscapeString(wildcardEscapedPath);
11341134
}
11351135

11361136
/// <summary>
@@ -1214,23 +1214,23 @@ public static string EscapePath(string path, bool escapeSpaces)
12141214
return WildcardEscapePath(path, escapeSpaces);
12151215
}
12161216

1217-
internal static string UnescapeWildcardEscapedPath(string globEscapedPath)
1217+
internal static string UnescapeWildcardEscapedPath(string wildcardEscapedPath)
12181218
{
12191219
// Prevent relying on my implementation if we can help it
1220-
if (!globEscapedPath.Contains('`'))
1220+
if (!wildcardEscapedPath.Contains('`'))
12211221
{
1222-
return globEscapedPath;
1222+
return wildcardEscapedPath;
12231223
}
12241224

1225-
var sb = new StringBuilder(globEscapedPath.Length);
1226-
for (int i = 0; i < globEscapedPath.Length; i++)
1225+
var sb = new StringBuilder(wildcardEscapedPath.Length);
1226+
for (int i = 0; i < wildcardEscapedPath.Length; i++)
12271227
{
12281228
// If we see a backtick perform a lookahead
1229-
char curr = globEscapedPath[i];
1230-
if (curr == '`' && i + 1 < globEscapedPath.Length)
1229+
char curr = wildcardEscapedPath[i];
1230+
if (curr == '`' && i + 1 < wildcardEscapedPath.Length)
12311231
{
12321232
// If the next char is an escapable one, don't add this backtick to the new string
1233-
char next = globEscapedPath[i + 1];
1233+
char next = wildcardEscapedPath[i + 1];
12341234
switch (next)
12351235
{
12361236
case '[':

src/PowerShellEditorServices/Workspace/Workspace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ internal string ResolveFilePath(string filePath)
373373
// Clients could specify paths with escaped space, [ and ] characters which .NET APIs
374374
// will not handle. These paths will get appropriately escaped just before being passed
375375
// into the PowerShell engine.
376-
filePath = PowerShellContext.UnescapeGlobEscapedPath(filePath);
376+
filePath = PowerShellContext.UnescapeWildcardEscapedPath(filePath);
377377

378378
// Get the absolute file path
379379
filePath = Path.GetFullPath(filePath);

test/PowerShellEditorServices.Test/Session/PathEscapingTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class PathEscapingTests
2323
[InlineData("/CJK.chars/脚本/[hello].ps1", "/CJK.chars/脚本/`[hello`].ps1")]
2424
[InlineData("C:\\Animals\\утка\\quack.ps1", "C:\\Animals\\утка\\quack.ps1")]
2525
[InlineData("C:\\&nimals\\утка\\qu*ck?.ps1", "C:\\&nimals\\утка\\qu`*ck`?.ps1")]
26-
public void CorrectlyGlobEscapesPaths_NoSpaces(string unescapedPath, string escapedPath)
26+
public void CorrectlyWildcardEscapesPaths_NoSpaces(string unescapedPath, string escapedPath)
2727
{
28-
string extensionEscapedPath = PowerShellContext.GlobEscapePath(unescapedPath);
28+
string extensionEscapedPath = PowerShellContext.WildcardEscapePath(unescapedPath);
2929
Assert.Equal(escapedPath, extensionEscapedPath);
3030
}
3131

@@ -43,9 +43,9 @@ public void CorrectlyGlobEscapesPaths_NoSpaces(string unescapedPath, string esca
4343
[InlineData("/CJK chars/脚本/[hello].ps1", "/CJK` chars/脚本/`[hello`].ps1")]
4444
[InlineData("C:\\Animal s\\утка\\quack.ps1", "C:\\Animal` s\\утка\\quack.ps1")]
4545
[InlineData("C:\\&nimals\\утка\\qu*ck?.ps1", "C:\\&nimals\\утка\\qu`*ck`?.ps1")]
46-
public void CorrectlyGlobEscapesPaths_Spaces(string unescapedPath, string escapedPath)
46+
public void CorrectlyWildcardEscapesPaths_Spaces(string unescapedPath, string escapedPath)
4747
{
48-
string extensionEscapedPath = PowerShellContext.GlobEscapePath(unescapedPath, escapeSpaces: true);
48+
string extensionEscapedPath = PowerShellContext.WildcardEscapePath(unescapedPath, escapeSpaces: true);
4949
Assert.Equal(escapedPath, extensionEscapedPath);
5050
}
5151

@@ -107,7 +107,7 @@ public void CorrectlyFullyEscapesPaths(string unescapedPath, string escapedPath)
107107
[InlineData("C:\\&nimals\\утка\\qu`*ck`?.ps1", "C:\\&nimals\\утка\\qu*ck?.ps1")]
108108
public void CorrectlyUnescapesPaths(string escapedPath, string expectedUnescapedPath)
109109
{
110-
string extensionUnescapedPath = PowerShellContext.UnescapeGlobEscapedPath(escapedPath);
110+
string extensionUnescapedPath = PowerShellContext.UnescapeWildcardEscapedPath(escapedPath);
111111
Assert.Equal(expectedUnescapedPath, extensionUnescapedPath);
112112
}
113113

0 commit comments

Comments
 (0)