Skip to content

Commit 55db24f

Browse files
committed
Change to only check one ParentAst
1 parent 1d4f3f6 commit 55db24f

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Rules/AvoidUsingInternalURLs.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
using System;
1414
using System.Collections.Generic;
15+
using System.Data.Odbc;
1516
using System.Linq;
1617
using System.Management.Automation.Language;
1718
using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic;
@@ -46,28 +47,24 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4647
{
4748
//Check if XPath is used. If XPath is used, then we don't throw warnings.
4849
Ast parentAst = expressionAst.Parent;
49-
IEnumerable<Ast> invocation = parentAst.FindAll(test => test is InvokeMemberExpressionAst, true);
50-
bool hasXPath = false;
51-
if (invocation != null)
50+
if (parentAst is InvokeMemberExpressionAst)
5251
{
53-
foreach (InvokeMemberExpressionAst ieAst in invocation)
52+
InvokeMemberExpressionAst invocation = parentAst as InvokeMemberExpressionAst;
53+
if (invocation != null)
5454
{
55-
if (String.Equals(ieAst.Member.ToString(), "SelectSingleNode",StringComparison.OrdinalIgnoreCase) ||
56-
String.Equals(ieAst.Member.ToString(), "SelectNodes",StringComparison.OrdinalIgnoreCase) ||
57-
String.Equals(ieAst.Member.ToString(), "Select",StringComparison.OrdinalIgnoreCase) ||
58-
String.Equals(ieAst.Member.ToString(), "Evaluate",StringComparison.OrdinalIgnoreCase) ||
59-
String.Equals(ieAst.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase))
55+
if (String.Equals(invocation.Member.ToString(), "SelectSingleNode",StringComparison.OrdinalIgnoreCase) ||
56+
String.Equals(invocation.Member.ToString(), "SelectNodes",StringComparison.OrdinalIgnoreCase) ||
57+
String.Equals(invocation.Member.ToString(), "Select", StringComparison.OrdinalIgnoreCase) ||
58+
String.Equals(invocation.Member.ToString(), "Evaluate",StringComparison.OrdinalIgnoreCase) ||
59+
String.Equals(invocation.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase))
6060
{
61-
hasXPath = true;
62-
break;
61+
continue;
6362
}
63+
6464
}
6565
}
66-
if (hasXPath)
67-
{
68-
continue;
69-
}
70-
66+
67+
7168
bool isPathValid = false;
7269
bool isInternalURL = false;
7370
//make sure there is no path

0 commit comments

Comments
 (0)