Check for whitespace at beginning of a watch pattern, requiring -force to continue #6360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I recently accidentally watched an expression with a space at the beginning completely unintentionally, as I was copy-pasting off of a list. In chat, this looks as though everything worked correctly and there is nothing wrong, but there's actually some hidden leading whitespace there.
This isn't the first time I've run into this problem. I've approved #5921 and #5789 (knowingly, I'll add) just to see if they would work, because the watch commands as viewed from chat would lead one to believe it was entered correctly. Naturally, the watches did not catch their intended targets in these instances.
What this PR does:
This addition checks for leading white space against the currently proposed pattern. If it's found, it throws a similar message at the user that #5114 introduced, and allows
-force
to be used to override.I know of no real reason why anyone would want to start a watch with whitespace, but given that SE chat shaves off leading whitespace visually (but does not functionally) it's 99 times out of 100 a mistake, and in my opinion, should warn the user about what they're doing while still preserving the ability to force the change through if thou happen-est to be that 1 user out of 100.
Potential improvements:
Did you even test this?
Yep, I did! I didn't have a spare sock so I just threw this against my own user and fired away. As a note, for this test there were two differences. One, I used
pattern.startswith(" ")
, which I changed to use regex considering #5928 did something similar and used regex (and this regex covers various whitespace characters, not just a "regular" space.) Two, the error message was very slightly different, and even then, only in punctuation and grammar (looks cleaner now, imo)Feel free to adjust this PR as fitting with the code practices used by Charcoalers, or request that I do so.