-
Notifications
You must be signed in to change notification settings - Fork 314
logic error #112
Description
Describe the bug
When a plugin performs case-insensitive str.replace or re.sub(..., flags=re.IGNORECASE) for a single ASCII or Cyrillic letter, the resulting text receives double the expected replacements, i.e. one “r/р” becomes “RRRR” instead of “RR”.
To Reproduce
Steps to reproduce the behavior:
0. write your vibe-pligin
- Install plugin
- Enable the plugin
- Send any message containing the letter
- Observe the sent text: every single letter is replaced by four letters. (letter depends on the content of the code, explanation below)
from base_plugin import BasePlugin, HookResult, HookStrategy
__id__ = "bug_demo"
__name__ = "Bug Demo"
__version__ = "1.0"
class Plugin(BasePlugin):
def on_plugin_load(self):
self.add_on_send_message_hook(100)
def on_send_message_hook(self, account, params):
if params.message:
# This single line reproduces the bug
params.message = params.message.replace('a', 'aa').replace('b', 'bb') \
return HookResult(strategy=HookStrategy.MODIFY, params=params)
return HookResult()
Expected behavior
A clear and concise description of what you expected to happen.
expected:
apple -> aaple, broke -> bbroke:
real:
apple -> aaaaple, broke -> bbbbroke
Screenshots
If applicable, add screenshots to help explain your problem.
no need
Smartphone (please complete the following information):
OnePlus 7 crdroid 11.6 Android 15
Additional context
Add any other context about the problem here.
The issue occurs only when the built-in Python runtime (Chaquopy) is used.
Work-around: avoid chained str.replace / re.sub with IGNORECASE ; instead use a single case-sensitive replace for each case. This suggests the runtime internally applies the replacement twice under case-insensitive conditions.