|
16 | 16 | using System.ComponentModel.Composition;
|
17 | 17 | using System.Globalization;
|
18 | 18 | using System.Collections.Generic;
|
| 19 | +using System.Linq; |
19 | 20 |
|
20 | 21 | namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
|
21 | 22 | {
|
@@ -49,11 +50,22 @@ public override bool ParameterCondition(CommandAst CmdAst, CommandElementAst CeA
|
49 | 50 |
|
50 | 51 | if (String.Equals(cmdParamAst.ParameterName, "computername", StringComparison.OrdinalIgnoreCase))
|
51 | 52 | {
|
52 |
| - Ast computerNameArgument = GetComputerNameArg(CmdAst, cmdParamAst.Extent.StartOffset); |
53 |
| - List<string> localhostExceptions = new List<string>{ "localhost", ".", "::1", "127.0.0.1" }; |
54 |
| - if ((null != computerNameArgument) && (!localhostExceptions.Contains(computerNameArgument.Extent.Text))) |
| 53 | + List<string> localhostRepresentations = new List<string> { "localhost", ".", "::1", "127.0.0.1" }; |
| 54 | + Ast computerNameArgument = GetComputerNameArg(CmdAst, cmdParamAst.Extent.StartOffset); |
| 55 | + |
| 56 | + if (null != computerNameArgument) |
| 57 | + { |
| 58 | + if (!localhostRepresentations.Contains(computerNameArgument.Extent.Text.ToLower())) |
| 59 | + { |
| 60 | + return computerNameArgument is ConstantExpressionAst; |
| 61 | + } |
| 62 | + |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + if (null != cmdParamAst.Argument && !localhostRepresentations.Contains(cmdParamAst.Argument.ToString().Replace("\"", "").Replace("'", "").ToLower())) |
55 | 67 | {
|
56 |
| - return cmdParamAst.Argument is ConstantExpressionAst || computerNameArgument is ConstantExpressionAst; |
| 68 | + return cmdParamAst.Argument is ConstantExpressionAst; |
57 | 69 | }
|
58 | 70 | }
|
59 | 71 | }
|
|
0 commit comments