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

Formatting characters may be grouped in Trigger in a surprising way #2590

Open
SnoopJ opened this issue Jan 27, 2024 · 1 comment
Open

Formatting characters may be grouped in Trigger in a surprising way #2590

SnoopJ opened this issue Jan 27, 2024 · 1 comment
Labels
Bug Things to squish; generally used for issues

Comments

@SnoopJ
Copy link
Contributor

SnoopJ commented Jan 27, 2024

Description

@dgw discovered that my Sopel instance's Unicode plugin was not recognizing italics in a message, even though bold is recognized just fine.

 8.4s unicode_summarize: 
      trigger.raw='@time=2024-01-27T01:42:25.541Z;account=SnoopJ :SnoopJ!~snoopj@user/snoopj PRIVMSG terribot :!u \x1d?' (file:///tmp/q19604111.txt),
      trigger.groups()=('u', '?', '?', None, None, None), s='?'

Where s = trigger.group(3)

It seems that this is because "\x02".isspace() is False and "\x1d".isspace() is True, so the latter is swallowed up into some of the \s baked into the rule automatically generated by Sopel when using @plugin.commands()

As a workaround, I have done the following in that plugin to get a more accurate reflection of the argument (while still ignoring spaces which are not interesting to that plugin's functionality):

cmd = trigger.group(1)
s = trigger.group(0)[len(cmd)+2:].replace(" ", "")

Reproduction steps

Write a command that would care to accept italic text, then observe that the formatting character is not in the groups() of the resulting Trigger.

Expected behavior

I would expect formatting characters to be treated as if they were normal text.

Relevant logs

No response

Notes

No response

Sopel version

973a489

Installation method

pip install

Python version

3.9.16

Operating system

Ubuntu 20.04

IRCd

No response

Relevant plugins

No response

@SnoopJ SnoopJ added the Bug Things to squish; generally used for issues label Jan 27, 2024
@dgw
Copy link
Member

dgw commented Jan 27, 2024

Contributing that 973a489 on Python 3.10.7 exhibits a related behavior in sopel-spongemock:

<dgw> .smock italic mocking
<Sopel> iTaLIc MoCkiNg

This command uses trigger.group(2). Note that the result is not italic because \x1d occurs between group 1 and 2. If \x1d appears in the middle of group 2 instead, it works as expected:

<dgw> .smock mocking italicly?
<Sopel> mOcKinG iTAliClY?

Thanks to @SnoopJ for helping track this down, and for writing up the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Things to squish; generally used for issues
Projects
None yet
Development

No branches or pull requests

2 participants