Skip to content

Commit

Permalink
Merge branch 'main' into users/bewhite/update-baselines-dec
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Dec 12, 2023
2 parents 806dab7 + 42b4f32 commit 0b99cc6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/CHANGELOG-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ What's changed since pre-release v1.32.0-B0053:
- Azure Kubernetes Service:
- Updated `Azure.AKS.Version` to use latest stable version `1.27.7` by @BernieWhite.
[#2581](https://github.com/Azure/PSRule.Rules.Azure/issues/2581)
- General improvements:
- Improved reporting of null argument in length function by @BernieWhite.
[#2597](https://github.com/Azure/PSRule.Rules.Azure/issues/2597)
- Engineering:
- Updated resource providers and policy aliases.
[#2579](https://github.com/Azure/PSRule.Rules.Azure/pull/2579)
- Bump Microsoft.SourceLink.GitHub to v8.0.0.
[#2538](https://github.com/Azure/PSRule.Rules.Azure/pull/2538)
- Bump BenchmarkDotNet.Diagnostics.Windows and BenchmarkDotNet to v0.13.11.
[#2575](https://github.com/Azure/PSRule.Rules.Azure/pull/2575)
- Bump Microsoft.CodeAnalysis.NetAnalyzers to v8.0.0.
[#2568](https://github.com/Azure/PSRule.Rules.Azure/pull/2568)

## v1.32.0-B0053 (pre-release)

Expand Down
14 changes: 14 additions & 0 deletions src/PSRule.Rules.Azure/Data/Template/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ internal static object Length(ITemplateContext context, object[] args)
if (CountArgs(args) != 1)
throw ArgumentsOutOfRange(nameof(Length), args);

if (IsNull(args[0]))
throw ArgumentNullNotExpected(nameof(Length));

if (ExpressionHelpers.TryString(args[0], out var s))
return (long)s.Length;
else if (args[0] is Array a)
Expand Down Expand Up @@ -2337,6 +2340,17 @@ private static TemplateFunctionException MismatchingResourceSegments(string expr
);
}

/// <summary>
/// One or more arguments for '{0}' are null when null was not expected.
/// </summary>
private static ExpressionArgumentException ArgumentNullNotExpected(string expression)
{
return new ExpressionArgumentException(
expression,
string.Format(Thread.CurrentThread.CurrentCulture, PSRuleResources.ArgumentNullNotExpected, expression)
);
}

#endregion Exceptions
}
}
2 changes: 1 addition & 1 deletion src/PSRule.Rules.Azure/PSRule.Rules.Azure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.4">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
9 changes: 9 additions & 0 deletions src/PSRule.Rules.Azure/Resources/PSRuleResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/PSRule.Rules.Azure/Resources/PSRuleResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="ArgumentInvalidStringArray" xml:space="preserve">
<value>The argument '{0}' for '{1}' is not a valid string array.</value>
</data>
<data name="ArgumentNullNotExpected" xml:space="preserve">
<value>One or more arguments for '{0}' are null when null was not expected.</value>
</data>
<data name="ArgumentsOutOfRange" xml:space="preserve">
<value>The number of arguments '{1}' is not within the allowed range for '{0}'.</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions tests/PSRule.Rules.Azure.Tests/FunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public void Length()

Assert.Throws<ExpressionArgumentException>(() => Functions.Length(context, null));
Assert.Throws<ExpressionArgumentException>(() => Functions.Length(context, System.Array.Empty<object>()));
Assert.Throws<ExpressionArgumentException>(() => Functions.Length(context, new object[] { null }));
}

[Fact]
Expand Down

0 comments on commit 0b99cc6

Please sign in to comment.