Skip to content

Commit f4ff1ae

Browse files
committed
Add checks for XPath for AvoidUsingInternalURL
1 parent a6180eb commit f4ff1ae

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Rules/AvoidUsingInternalURLs.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4444
{
4545
foreach (StringConstantExpressionAst expressionAst in expressionAsts)
4646
{
47+
//Check if XPath is used. If XPath is used, then we don't throw warnings.
48+
Ast parentAst = expressionAst.Parent;
49+
IEnumerable<Ast> invocation = parentAst.FindAll(test => test is InvokeMemberExpressionAst, true);
50+
bool hasXPath = false;
51+
if (invocation != null)
52+
{
53+
foreach (InvokeMemberExpressionAst ieAst in invocation)
54+
{
55+
if (String.Equals(ieAst.Member.ToString(), "SelectSingleNode",StringComparison.OrdinalIgnoreCase) ||
56+
String.Equals(ieAst.Member.ToString(), "SelectNodes",StringComparison.OrdinalIgnoreCase))
57+
{
58+
hasXPath = true;
59+
break;
60+
}
61+
}
62+
}
63+
if (hasXPath)
64+
{
65+
continue;
66+
}
67+
4768
bool isPathValid = false;
4869
bool isInternalURL = false;
4970
//make sure there is no path

Tests/Rules/AvoidUsingInternalURLs.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ $internalSite = "//msw"
33
$externalSite = "http:\\msw"
44
if (-not $scratch.EndsWith("/")) {
55
$scratch += "/";
6-
}
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
$correctPath = "www.bing.com"
22
$externalSite = "//outside.co/test"
33
rmdir /s /q ".\Directory"
4+
function Test
5+
{
6+
$filesNode = $infoXml.SelectSingleNode("//files")
7+
}
48
$sd = "O:BAG:BAD:(A;;0x800;;;WD)(A;;0x120fff;;;SY)(A;;0x120fff;;;LS)(A;;0x120fff;;;NS)(A;;0x120fff;;;BA)(A;;0xee5;;;LU)(A;;LC;;;MU)(A;;0x800;;;AG)"

0 commit comments

Comments
 (0)