Skip to content

Commit

Permalink
Added fixes for link and sub-selectors #1393 #1394 (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Dec 20, 2022
1 parent 55aceed commit 350695e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
8 changes: 8 additions & 0 deletions docs/CHANGELOG-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/PSRule/Definitions/Expressions/ExpressionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResultReason>();
Expand All @@ -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<ResultReason>();
Expand Down
17 changes: 13 additions & 4 deletions src/PSRule/Definitions/Expressions/LanguageExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion src/PSRule/Rules/RuleHelpInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal static bool HasOnlineHelp(this IRuleHelpInfoV2 info)
/// <param name="url">A URL to the online help location.</param>
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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PSRule/Runtime/RunspaceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 350695e

Please sign in to comment.