-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
choose: safely handle formatted options #1965
Conversation
This is for plugin convenience, as otherwise they'd all need to build their own lists of constants from the formatting module. Providing a constant also lets plugins adapt automatically when Sopel adds support for new formatting characters.
Wow, I really whiffed that. Was so focused on making sure my new tests behaved that I neglected the existing ones. |
da02739
to
967f747
Compare
Python's built-in `strip()` method for strings considers some control codes used for IRC formatting to be "whitespace" and removes them if they appear at the beginning or end of the string. While the built-in method does take an optional argument listing what characters to strip, there's no good way to generate our own list to pass in. One can look up the category of a Unicode character, but there's no way to get a list of all characters in a category. So instead, we have a custom function, which also handles adding the "formatting reset" character if the text contains any formatting. (My original idea was to write a "parser" of sorts that would insert the appropriate control code to "close" unmatched formatting, but then I remembered that the "reset" 0x0F exists and it was Good Enough™.) Future revisions could gain a little more efficiency on the wire by only adding the reset character if the text contains an unmatched formatting code (but that quickly devolves into diminishing returns, so it's likely not worth doing unless someone gets *really* bored).
967f747
to
078c4ac
Compare
Should be all fixed, or at least the full |
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.
As far as I'm concerned, it works and it does the job, so good for me.
Well OK yes I suggested some changes, but they are pretty minor.
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.
Co-authored-by: Exirel <florian.strzelecki@gmail.com>
I'm going to stop messing with this now. 23 passing + 8 xfail test cases is enough for this one silly little function. 😛 |
0c763cf
to
c89fa55
Compare
Because Python doesn't have a static type system.
c89fa55
to
582baad
Compare
Yeah, that didn't happen. But I'm really done now. CI passed on all versions this time! |
Description
Briefly, this resolves #1877. No longer will unterminated formatting, or leading/trailing formatting characters, cause formatting issues in the
.choose
command's output.The custom "strip"/"cleanup" function that makes it all possible comes replete with
162023 passing cases and 8 expect-fail cases for future enhancements—though I'm sure there are weird cases I haven't covered with the existing test params. Suggestions welcome, and/or we can just see what breaks once this hits the wild.Checklist
make qa
(runsmake quality
andmake test
)