errbot icon indicating copy to clipboard operation
errbot copied to clipboard

Plugin config through Slack fails because of Unicode characters

Open jcfrt opened this issue 1 year ago • 1 comments

Describe the bug Using !plugin config MyPlugin {"key": "value"} from the Slack client does not work because the Slack client (on MacOS) forces the use of unicode characters for double and single quotes:

  • double quotes “ (U+201C) and ” (U+201D)
  • single quotes ‘ (U+2018) and ’ (U+2019)

Getting the following error in logs:

ERROR    errbot.plugins.Plugins    Invalid expression for the configuration of the plugin
Traceback (most recent call last):
  File "errbot/core_plugins/plugins.py", line 187, in plugin_config
    real_config_obj = literal_eval(" ".join(args[1:]))
  File "/usr/local/lib/python3.10/ast.py", line 62, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
  File "/usr/local/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    {<E2><80><98>key<E2><80><99>: <E2><80><98>value<E2><80><99>}
     ^
SyntaxError: invalid character '<E2><80><98>' (U+2018)

To Reproduce

  • For a given plugin with basic config template:
from errbot import BotPlugin
class PluginExample(BotPlugin):
    def get_configuration_template(self):
        return {'key': 'value'}
  • Use the official (Chromium-based) Slack client on MacOS
  • send the following to errbot !plugin config PluginExample
  • the reply will be

Default configuration for this plugin (you can copy and paste this directly as a command): !plugin config PluginExample {'key': 'value'}

  • Copy and paste the given message will result in the following (note the unicode quotes)

!plugin config PluginExample {‘key’: ‘value’}

  • Error message in logs as mentioned above

Expected behavior The character string polluted with unicode should be parsed; unicode characters replaced with ASCII equivalent.

Environment (please complete the following information):

  • Errbot version: 6.1.9
  • OS version: Linux
  • Python version: 3.10
  • Using a virtual environment: yes
  • Using Docker: no

jcfrt avatar May 01 '24 17:05 jcfrt

Found a workaround: disable the smart quotes feature globally in MacOS

# Disable smart quotes as they’re annoying when typing code.
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false

jcfrt avatar May 01 '24 17:05 jcfrt