Skip to content

Commit b4e890c

Browse files
committed
Merge pull request #257 from PowerShell/BugFixes
Take Bug fixes to Master
2 parents 2938f24 + 96d56c3 commit b4e890c

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ private void ProcessPath(string path)
255255
}
256256
}
257257
else if (File.Exists(path))
258-
{
259-
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseFileMessage, path));
258+
{
260259
if ((path.Length > ps1Suffix.Length && path.Substring(path.Length - ps1Suffix.Length).Equals(ps1Suffix, StringComparison.OrdinalIgnoreCase)) ||
261260
(path.Length > psm1Suffix.Length && path.Substring(path.Length - psm1Suffix.Length).Equals(psm1Suffix, StringComparison.OrdinalIgnoreCase)) ||
262261
(path.Length > psd1Suffix.Length && path.Substring(path.Length - psd1Suffix.Length).Equals(psd1Suffix, StringComparison.OrdinalIgnoreCase)))
263262
{
263+
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseFileMessage, path));
264264
AnalyzeFile(path);
265265
}
266266
}

Rules/AvoidUsingInternalURLs.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
//
1212

1313
using System;
14+
using System.Collections;
1415
using System.Collections.Generic;
1516
using System.Linq;
17+
using System.Linq.Expressions;
1618
using System.Management.Automation.Language;
1719
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
1820
using System.ComponentModel.Composition;
@@ -44,8 +46,19 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4446
{
4547
foreach (StringConstantExpressionAst expressionAst in expressionAsts)
4648
{
47-
//Check if XPath is used. If XPath is used, then we don't throw warnings.
49+
4850
Ast parentAst = expressionAst.Parent;
51+
//Check if -replace is used, if it is string replace, we don't throw warnings.
52+
Ast grandParentAst = parentAst.Parent;
53+
if (grandParentAst is BinaryExpressionAst)
54+
{
55+
if ((grandParentAst as BinaryExpressionAst).Operator.Equals(TokenKind.Ireplace))
56+
{
57+
continue;
58+
}
59+
}
60+
61+
//Check if XPath is used. If XPath is used, then we don't throw warnings.
4962
if (parentAst is InvokeMemberExpressionAst)
5063
{
5164
InvokeMemberExpressionAst invocation = parentAst as InvokeMemberExpressionAst;
@@ -55,7 +68,9 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
5568
String.Equals(invocation.Member.ToString(), "SelectNodes",StringComparison.OrdinalIgnoreCase) ||
5669
String.Equals(invocation.Member.ToString(), "Select", StringComparison.OrdinalIgnoreCase) ||
5770
String.Equals(invocation.Member.ToString(), "Evaluate",StringComparison.OrdinalIgnoreCase) ||
58-
String.Equals(invocation.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase))
71+
String.Equals(invocation.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase) ||
72+
String.Equals(invocation.Expression.ToString(), "[System.String]",StringComparison.OrdinalIgnoreCase) ||
73+
String.Equals(invocation.Expression.ToString(), "[String]", StringComparison.OrdinalIgnoreCase))
5974
{
6075
continue;
6176
}

Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ function Test
55
{
66
$filesNode = $infoXml.SelectSingleNode("//files")
77
}
8-
$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)"
8+
$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)"
9+
$msg = [System.String]::Format("1:{0}", "test")
10+
$internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType()

0 commit comments

Comments
 (0)