Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation to address. Fixes #15452. #15602

Closed
wants to merge 2 commits into from

Conversation

rwawr
Copy link
Contributor

@rwawr rwawr commented Mar 27, 2024

Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation to address. Fixes #15452.

…displayed and the operation for the given condition is a negation.
@rwawr
Copy link
Contributor Author

rwawr commented Mar 27, 2024 via email

@rwawr rwawr changed the title Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation. Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation to address #15452. Mar 27, 2024
@rwawr rwawr changed the title Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation to address #15452. Adjust content type condition to evaluate to true when no content is displayed and the operation for the given condition is a negation to address. Fixes #15452. Mar 27, 2024
@Piedone
Copy link
Member

Piedone commented Mar 27, 2024

Congrats on your first contribution, and thank you! There's something strange going on with the policy bot, could you please comment here (not reply in an e-mail) just this?

@dotnet-policy-service agree company="AdvantageCS"

@rwawr
Copy link
Contributor Author

rwawr commented Mar 27, 2024

@dotnet-policy-service agree company="AdvantageCS"

@@ -43,6 +44,14 @@ public ValueTask<bool> EvaluateAsync(Condition condition)
private ValueTask<bool> EvaluateAsync(ContentTypeCondition condition)
{
var operatorComparer = _operatorResolver.GetOperatorComparer(condition.Operation);

// If no content types are considered and the operation is an INegateOperator, return true,
// since displaying no content type should match any negative comparision on any content type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// since displaying no content type should match any negative comparision on any content type
// since displaying no content type should match any negative comparison on any content type

Comment on lines 50 to 53
if (!_contentTypes.Any() && condition.Operation is INegateOperator)
{
return ValueTask.FromResult(true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can say that this will be correct for all INegateOperator implementations (the current built-in ones, yes, but this isn't necessarily future-proof and appropriate for third-party implementations). How about running operatorComparer with an empty string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought about that. I was originally thinking I only wanted to do that for negative comparisons, but you're right, that should return the expected result (false) for the other comparisons as well. I'll go ahead and make that change.

@Piedone
Copy link
Member

Piedone commented Mar 27, 2024

Hmm, I don't know what's with the bot. Please open a new PR, let the bot run (it should), and add the same reply in a comment.

@rwawr
Copy link
Contributor Author

rwawr commented Mar 27, 2024

Hmm, I don't know what's with the bot. Please open a new PR, let the bot run (it should), and add the same reply in a comment.

Will do!

…ssuming all implementations of INegateOperation should return true when no content types are considered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content Type layer rule behaves unexpectedly on pages where no content is displayed with "Detail" display type
2 participants