Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ private void ProcessPath(string path)
}
}
else if (File.Exists(path))
{
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseFileMessage, path));
{
if ((path.Length > ps1Suffix.Length && path.Substring(path.Length - ps1Suffix.Length).Equals(ps1Suffix, StringComparison.OrdinalIgnoreCase)) ||
(path.Length > psm1Suffix.Length && path.Substring(path.Length - psm1Suffix.Length).Equals(psm1Suffix, StringComparison.OrdinalIgnoreCase)) ||
(path.Length > psd1Suffix.Length && path.Substring(path.Length - psd1Suffix.Length).Equals(psd1Suffix, StringComparison.OrdinalIgnoreCase)))
{
WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.VerboseFileMessage, path));
AnalyzeFile(path);
}
}
Expand Down
19 changes: 17 additions & 2 deletions Rules/AvoidUsingInternalURLs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Management.Automation.Language;
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
using System.ComponentModel.Composition;
Expand Down Expand Up @@ -44,8 +46,19 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
{
foreach (StringConstantExpressionAst expressionAst in expressionAsts)
{
//Check if XPath is used. If XPath is used, then we don't throw warnings.

Ast parentAst = expressionAst.Parent;
//Check if -replace is used, if it is string replace, we don't throw warnings.
Ast grandParentAst = parentAst.Parent;
if (grandParentAst is BinaryExpressionAst)
{
if ((grandParentAst as BinaryExpressionAst).Operator.Equals(TokenKind.Ireplace))
{
continue;
}
}

//Check if XPath is used. If XPath is used, then we don't throw warnings.
if (parentAst is InvokeMemberExpressionAst)
{
InvokeMemberExpressionAst invocation = parentAst as InvokeMemberExpressionAst;
Expand All @@ -55,7 +68,9 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
String.Equals(invocation.Member.ToString(), "SelectNodes",StringComparison.OrdinalIgnoreCase) ||
String.Equals(invocation.Member.ToString(), "Select", StringComparison.OrdinalIgnoreCase) ||
String.Equals(invocation.Member.ToString(), "Evaluate",StringComparison.OrdinalIgnoreCase) ||
String.Equals(invocation.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase))
String.Equals(invocation.Member.ToString(), "Matches",StringComparison.OrdinalIgnoreCase) ||
String.Equals(invocation.Expression.ToString(), "[System.String]",StringComparison.OrdinalIgnoreCase) ||
String.Equals(invocation.Expression.ToString(), "[String]", StringComparison.OrdinalIgnoreCase))
{
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/Rules/AvoidUsingInternalURLsNoViolations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ function Test
{
$filesNode = $infoXml.SelectSingleNode("//files")
}
$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)"
$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)"
$msg = [System.String]::Format("1:{0}", "test")
$internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType()