diff --git a/docs/CHANGELOG-v2.md b/docs/CHANGELOG-v2.md index 4c875d6350..f3c361d7d7 100644 --- a/docs/CHANGELOG-v2.md +++ b/docs/CHANGELOG-v2.md @@ -30,6 +30,14 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers ## Unreleased +What's changed since pre-release v2.7.0-B0097: + +- Bug fixes: + - Fixed null reference for link property by @BernieWhite. + [#1393](https://github.com/microsoft/PSRule/issues/1393) + - Fixed reason are emitted for pre-condition sub-selectors by @BernieWhite. + [#1394](https://github.com/microsoft/PSRule/issues/1394) + ## v2.7.0-B0097 (pre-release) What's changed since pre-release v2.7.0-B0070: diff --git a/src/PSRule/Definitions/Expressions/ExpressionContext.cs b/src/PSRule/Definitions/Expressions/ExpressionContext.cs index d0687e6067..624c7c6bea 100644 --- a/src/PSRule/Definitions/Expressions/ExpressionContext.cs +++ b/src/PSRule/Definitions/Expressions/ExpressionContext.cs @@ -80,7 +80,7 @@ internal void PopScope(RunspaceScope scope) public void Reason(IOperand operand, string text, params object[] args) { - if (string.IsNullOrEmpty(text)) + if (string.IsNullOrEmpty(text) || !RunspaceContext.CurrentThread.IsScope(RunspaceScope.Rule)) return; _Reason ??= new List(); @@ -89,7 +89,7 @@ public void Reason(IOperand operand, string text, params object[] args) public void Reason(string text, params object[] args) { - if (string.IsNullOrEmpty(text)) + if (string.IsNullOrEmpty(text) || !RunspaceContext.CurrentThread.IsScope(RunspaceScope.Rule)) return; _Reason ??= new List(); diff --git a/src/PSRule/Definitions/Expressions/LanguageExpressions.cs b/src/PSRule/Definitions/Expressions/LanguageExpressions.cs index 55f206c995..c4c3a37c76 100644 --- a/src/PSRule/Definitions/Expressions/LanguageExpressions.cs +++ b/src/PSRule/Definitions/Expressions/LanguageExpressions.cs @@ -205,11 +205,20 @@ private static LanguageExpressionOuterFn PreconditionSubselector(LanguageExpress { return (context, o) => { - // Evalute sub-selector pre-condition - if (!AcceptsSubselector(context, subselector, o)) + try { - context.Debug(PSRuleResources.DebugTargetSubselectorMismatch); - return null; + context.PushScope(RunspaceScope.Precondition); + + // Evalute sub-selector pre-condition + if (!AcceptsSubselector(context, subselector, o)) + { + context.Debug(PSRuleResources.DebugTargetSubselectorMismatch); + return null; + } + } + finally + { + context.PopScope(RunspaceScope.Precondition); } return fn(context, o); }; diff --git a/src/PSRule/Rules/RuleHelpInfo.cs b/src/PSRule/Rules/RuleHelpInfo.cs index a1794da360..d238b35bf2 100644 --- a/src/PSRule/Rules/RuleHelpInfo.cs +++ b/src/PSRule/Rules/RuleHelpInfo.cs @@ -85,7 +85,7 @@ internal static bool HasOnlineHelp(this IRuleHelpInfoV2 info) /// A URL to the online help location. internal static void SetOnlineHelpUrl(this IRuleHelpInfoV2 info, string url) { - if (info == null || info.Annotations == null) return; + if (info == null || info.Annotations == null || string.IsNullOrEmpty(url)) return; info.Annotations[ONLINE_HELP_LINK_ANNOTATION] = url; } } diff --git a/src/PSRule/Runtime/RunspaceContext.cs b/src/PSRule/Runtime/RunspaceContext.cs index 0b248e14ea..7ed138e5a6 100644 --- a/src/PSRule/Runtime/RunspaceContext.cs +++ b/src/PSRule/Runtime/RunspaceContext.cs @@ -576,12 +576,12 @@ internal SourceScope EnterSourceScope(SourceFile source) { // TODO: Look at scope caching, and a scope stack. - if (!source.Exists()) - throw new FileNotFoundException(PSRuleResources.ScriptNotFound, source.Path); - if (Source != null && Source.File == source) return Source; + if (!source.Exists()) + throw new FileNotFoundException(PSRuleResources.ScriptNotFound, source.Path); + _LanguageScopes.UseScope(source.Module); // Change scope