dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Fix Guard IsWhiteSpace and IsNotWhiteSpace Methods

Open GabrieleMessina opened this issue 2 years ago • 2 comments

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

  • [x] Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • [x] Based off latest main branch of toolkit
  • [x] PR doesn't include merge commits (always rebase on top of our main, if needed)
  • [x] 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)
  • [x] 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
  • [x] Code follows all style conventions

Other information

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

GabrieleMessina avatar Mar 18 '23 14:03 GabrieleMessina

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.

cremor avatar Mar 30 '23 15:03 cremor

@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.

GabrieleMessina avatar Apr 16 '23 15:04 GabrieleMessina