-
-
Notifications
You must be signed in to change notification settings - Fork 498
Replace null checks with IsEmpty property for ReadOnlySpan<char> #916
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
base: master
Are you sure you want to change the base?
Conversation
This change suppresses CA2265 warnings.
There was a problem hiding this 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
nullassignment withReadOnlySpan<char>.Emptyfor the normalized variable - Changes null check from
normalized != nullto!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++) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
This PR replace null checks with
IsEmptyproperty forReadOnlySpan<char>.The change suppresses CA2265 warnings.