Skip to content

Commit 0c1ea1f

Browse files
committed
Apply review suggestions
1 parent 5cd5061 commit 0c1ea1f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/PowerShellEditorServices/Language/FindDotSourcedVisitor.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ private string GetPathFromExpandableStringExpression(ExpandableStringExpressionA
7676
foreach (var nestedExpression in expandableStringExpressionAst.NestedExpressions)
7777
{
7878
// If the string contains the variable $PSScriptRoot, we replace it with the corresponding value.
79-
if (nestedExpression is VariableExpressionAst variableExpressionAst
80-
&& variableExpressionAst.VariablePath.UserPath.Equals("PSScriptRoot", StringComparison.OrdinalIgnoreCase))
79+
if (!(nestedExpression is VariableExpressionAst variableAst
80+
&& variableAst.VariablePath.UserPath.Equals("PSScriptRoot", StringComparison.OrdinalIgnoreCase)))
8181
{
82-
path = path.Replace(variableExpressionAst.ToString(), _psScriptRoot);
83-
}
84-
else
85-
{
86-
return null; // We're going to get an invalid path anyway.
82+
return null; // We return null instead of a partially evaluated ExpandableStringExpression.
8783
}
84+
85+
path = path.Replace(variableAst.ToString(), _psScriptRoot);
8886
}
8987

9088
return path;

src/PowerShellEditorServices/Language/LanguageService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ await CommandHelpers.GetCommandInfo(
497497
private static string GetDotSourcedPath(SymbolReference symbol, Workspace workspace, ScriptFile scriptFile)
498498
{
499499
string cleanedUpSymbol = PathUtils.NormalizePathSeparators(symbol.SymbolName.Trim('\'', '"'));
500-
return workspace.ResolveRelativeScriptPath(Path.GetDirectoryName(scriptFile.FilePath),
501-
Regex.Replace(cleanedUpSymbol, @"\$PSScriptRoot|\${PSScriptRoot}", Path.GetDirectoryName(scriptFile.FilePath), RegexOptions.IgnoreCase));
500+
string psScriptRoot = Path.GetDirectoryName(scriptFile.FilePath);
501+
return workspace.ResolveRelativeScriptPath(psScriptRoot,
502+
Regex.Replace(cleanedUpSymbol, @"\$PSScriptRoot|\${PSScriptRoot}", psScriptRoot, RegexOptions.IgnoreCase));
502503
}
503504

504505
/// <summary>

0 commit comments

Comments
 (0)