Skip to content

Conversation

@prozolic
Copy link
Contributor

This PR replace null checks with IsEmpty property for ReadOnlySpan<char>.
The change suppresses CA2265 warnings.

Copilot AI review requested due to automatic review settings November 28, 2025 23:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to replace null checks with the IsEmpty property for ReadOnlySpan<char> variables to suppress CA2265 warnings. The changes update the LinkHelper.Urilize method to use span-based empty checks instead of null checks.

  • Replaces null assignment with ReadOnlySpan<char>.Empty for the normalized variable
  • Changes null check from normalized != null to !normalized.IsEmpty

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

normalized = allowOnlyAscii ? CharNormalizer.ConvertToAscii(c) : ReadOnlySpan<char>.Empty;
}

for (int j = 0; j < (normalized.Length < 1 ? 1 : normalized.Length); j++)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we missing test coverage given that a null normalized would throw here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MihaZupan Thank you for the review.
Since normalized is a ReadOnlySpan<char>, I changed the check from normalized != null to !normalized.IsEmpty.
When CharNormalizer.ConvertToAscii(c) returns null, it is implicitly converted to an empty span, maintaining the same behavior as before.
I confirmed from the following test cases.

https://github.com/xoofx/markdig/blob/master/src/Markdig.Tests/TestLinkHelper.cs#L330-L337

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, I was more referring to whether there are cases that could trigger an exception to be thrown before your current change. If so, it'd be good to have a test case for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point, I cannot find any cases where an exception would be thrown before my change.
If an empty string ("") were assigned to normalized, the results of normalized != null and !normalized.IsEmpty would differ, which could cause an exception. However, I cannot find any cases where CharNormalizer.ConvertToAscii would return an empty string ("").
Does this response address your concern?

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.

2 participants