Skip to content

Commit

Permalink
Fix ArgumentOutOfRangeException in PowerShellPostAmpersandEscape. (#2875
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TingluoHuang authored Sep 21, 2023
1 parent 8c917b4 commit 67d7080
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Sdk/DTLogging/Logging/ValueEncoders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ public static String PowerShellPostAmpersandEscape(String value)
var secretSection = string.Empty;
if (value.Contains("&+"))
{
// +1 to skip the letter that got colored
secretSection = value.Substring(value.IndexOf("&+") + "&+".Length + 1);
if (value.Length > value.IndexOf("&+") + "&+".Length + 1)
{
// +1 to skip the letter that got colored
secretSection = value.Substring(value.IndexOf("&+") + "&+".Length + 1);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/Test/L0/HostContextL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void DefaultSecretMaskers()
[InlineData("secret&+secret&secret", "secret&+\x0033[96ms\x0033[0mecret&secret", "***\x0033[96ms\x0033[0m***")]
[InlineData("secret&+secret&+secret", "secret&+\x0033[96ms\x0033[0mecret&+secret", "***\x0033[96ms\x0033[0m***")]
[InlineData("secret&+secret&secret&+secret", "secret&+\x0033[96ms\x0033[0mecret&secret&+secret", "***\x0033[96ms\x0033[0m***")]
[InlineData("secret&secret&+", "secret&secret&+\x0033[96m\x0033[0m", "***\x0033[96m\x0033[0m")]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void SecretSectionMasking(string secret, string rawOutput, string maskedOutput)
Expand Down

0 comments on commit 67d7080

Please sign in to comment.