Skip to content

Commit 301fa8a

Browse files
committed
Merge branch 'XPath' into BugFixes
2 parents a6180eb + fe6d977 commit 301fa8a

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Rules/AvoidUsingInternalURLs.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ 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+
if (parentAst is InvokeMemberExpressionAst)
50+
{
51+
InvokeMemberExpressionAst invocation = parentAst as InvokeMemberExpressionAst;
52+
if (invocation != null)
53+
{
54+
if (String.Equals(invocation.Member.ToString(), "SelectSingleNode",StringComparison.OrdinalIgnoreCase) ||
55+
String.Equals(invocation.Member.ToString(), "SelectNodes",StringComparison.OrdinalIgnoreCase) ||
56+
String.Equals(invocation.Member.ToString(), "Select", StringComparison.OrdinalIgnoreCase) ||
57+
String.Equals(invocation.Member.ToString(), "Evaluate",StringComparison.OrdinalIgnoreCase) ||
58+
String.Equals(invocation.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase))
59+
{
60+
continue;
61+
}
62+
63+
}
64+
}
65+
66+
4767
bool isPathValid = false;
4868
bool isInternalURL = false;
4969
//make sure there is no path
@@ -128,7 +148,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
128148
new DiagnosticRecord(
129149
String.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingInternalURLsError,
130150
expressionAst.Value), expressionAst.Extent,
131-
GetName(), DiagnosticSeverity.Warning, fileName);
151+
GetName(), DiagnosticSeverity.Information, fileName);
132152

133153
}
134154
}
@@ -177,7 +197,7 @@ public SourceType GetSourceType()
177197
/// <returns></returns>
178198
public RuleSeverity GetSeverity()
179199
{
180-
return RuleSeverity.Warning;
200+
return RuleSeverity.Information;
181201
}
182202

183203
/// <summary>

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Describe "TestSeverity" {
118118

119119
It "filters rules based on multiple severity inputs"{
120120
$rules = Get-ScriptAnalyzerRule -Severity Error,Information
121-
$rules.Count | Should be 9
121+
$rules.Count | Should be 13
122122
}
123123

124124
It "takes lower case inputs" {
@@ -130,11 +130,11 @@ Describe "TestSeverity" {
130130
Describe "TestWildCard" {
131131
It "filters rules based on the -Name wild card input" {
132132
$rules = Get-ScriptAnalyzerRule -Name PSDSC*
133-
$rules.Count | Should be 4
133+
$rules.Count | Should be 6
134134
}
135135

136136
It "filters rules based on wild card input and severity"{
137137
$rules = Get-ScriptAnalyzerRule -Name PSDSC* -Severity Information
138-
$rules.Count | Should be 1
138+
$rules.Count | Should be 3
139139
}
140140
}

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Describe "Test IncludeRule" {
141141

142142
it "includes 2 wildcardrules" {
143143
$includeWildcard = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $avoidRules, $useRules
144-
$includeWildcard.Count | Should be 7
144+
$includeWildcard.Count | Should be 9
145145
}
146146
}
147147
}

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)