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

Fix Guard IsWhiteSpace and IsNotWhiteSpace Methods #650

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

GabrieleMessina
Copy link
Contributor

Closes #441

Fixed Guard IsWhiteSpace and IsNotWhiteSpace methods adding a check for null before calling string.IsNullOrWhiteSpace.
Added some tests for both methods.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tested code with current supported SDKs
  • New component
    • Pull Request has been submitted to the documentation repository instructions. Link:
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

I don't know if this can be considered a breaking change.

@cremor
Copy link

cremor commented Mar 30, 2023

In my opinion those methods are still confusing with this PR. Why does "white space" include an empty string, but doesn't include null? Neither are white-space characters. Just from the method name I'd assume that an empty string would fail the Guard.IsWhiteSpace call.

But I can see how the method name is similar to String.IsNullOrWhiteSpace, which also includes empty strings. But that method also explicitly mentions empty strings in its documentation.

So, at least I'd suggest to change the documentation of those methods to also mention empty strings.
For even better distinction I would suggest to only allow white-space characters in Guard.IsWhiteSpace and add additional methods for Guard.IsEmptyOrWhiteSpace.

@GabrieleMessina
Copy link
Contributor Author

@cremor I think you have a point. I'll change the code as soon as I can.
I'm not so sure, though, about the new Guard.IsEmptyOrWhiteSpace method because it can be achieved using a combination of the other Guard methods and I don't think it'll be widely used.

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.

Guard.IsNotWhiteSpace gives exception on null value
2 participants