1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00
John Hernandez db96d13453
Improve string convertion error handling
Before the change, profanity has shown
`TypeError: prof_pre_chat_message_display() missing 3 required positional arguments: 'barejid',
           'resource', and 'message'`
error for received messages with incorrect encoding
instead of proper error handling for string convertion.

That is a temporary fix, correct fix probably would be
passing potentially problematic char* as `bytes` (using `y` instead of `s` format),
but this would require API changes and hence correction of plugins to
handle new input parameters properly (likely with "decode" function).

A bit hard to reproduce. You need to add a plugin with the following code
(or any other plugin with `prof_pre_chat_message_display` present, such as emoticons.py):
```python
def prof_pre_chat_message_display(barejid, resource, message):
    return message
```

and then receive/send message with incorrectly encoded character, it can be any
invalid UTF8 symbol. You'll see error in console, errors don't represent actual
errors in plugins, but rather Profanity's shortcoming, though it make appear so
that the problem is in plugin.

Actual proper handling would likely be using `y` instead of `s` format
(see [reference](https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue))

> s ([str](https://docs.python.org/3/library/stdtypes.html#str) or None) [const char *]
>    Convert a null-terminated C string to a Python [str](https://docs.python.org/3/library/stdtypes.html#str)
object using 'utf-8' encoding. If the C string pointer is NULL, None is used.

to

> y ([bytes](https://docs.python.org/3/library/stdtypes.html#bytes)) [const char *]
>     This converts a C string to a Python [bytes](https://docs.python.org/3/library/stdtypes.html#bytes)
> object. If the C string pointer is NULL, None is returned.

since there is a [problem](https://docs.python.org/3/c-api/arg.html) with `s`:
> s ([str](https://docs.python.org/3/library/stdtypes.html#str)) [const char *]
>    Convert a Unicode object to a C pointer to a character string.
> A pointer to an existing string is stored in the character pointer variable whose address you pass.
> ... Unicode objects are converted to C strings using 'utf-8' encoding.
> **If this conversion fails**, a [UnicodeError](https://docs.python.org/3/library/exceptions.html#UnicodeError) is raised.

In python such problem can be handled using `errors='ignore'` in [bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) or in a more sophisticated manner, depending on needs and realization.
2023-11-22 09:29:31 +01:00
2021-12-24 13:49:07 +01:00
2023-11-13 09:40:04 +01:00
2016-03-09 12:55:57 +01:00
2023-11-11 10:04:38 +01:00
2022-02-01 15:01:28 +01:00
2023-10-04 17:02:10 +02:00
2023-10-14 18:07:52 +02:00
2023-08-03 08:06:19 +02:00
2021-08-26 00:30:55 +00:00
2022-08-18 15:03:38 +02:00
2022-08-18 15:02:36 +02:00
2019-04-24 01:08:38 +02:00
2019-07-11 14:25:42 +02:00
2023-08-23 10:49:57 +02:00
2023-08-25 20:11:26 +02:00
2023-03-10 11:20:59 +01:00
2020-05-21 09:16:18 +02:00

Profanity

Build Status GitHub contributors Packaging status

Profanity is a console based XMPP client inspired by Irssi.

If you like Profanity consider becoming a sponsor or donate some money.

alt tag

See the User Guide for information on installing and using Profanity.

Project

This project is about freedom, privacy and choice. We want to enable people to chat with one another in a safe way. Thus supporting encryption (OTR, PGP, OMEMO, OX) and being decentralized, meaning everyone can run their own server. We believe XMPP is a great proven protocol with an excellent community serving this purpose well.

Feel free to follow us on twitter, join our mailing list and/or MUC.

Installation

Our user guide contains an install section and a section for building from source yourself.

Donations

We would highly appreciate it if you support us via GitHub Sponsors. Especially if you make feature requests or need help using Profanity. Sponsoring enables us to spend time on Profanity.

An alternative way to support us would be to ask for our IBAN or use Bitcoin: bc1qx265eat7hfasqkqmk9qf38delydnrnuvzhzy0x.

Issues backed by a sponsor will be tagged with the sponsored label. Feature requests that we consider out of scope, either because of interest or because of time needed to implement them, will be marked with the unfunded label.

Another way to sponsor us or get an issue solved is to comment on an issue that you are willing to sponsor it.

Tasks from our sponsors will be tackled first.

Thank you! <3

How to contribute

We tried to sum things up on our helpout page. Additionally you can check out our blog where we have articles like: How to get a backtrace and Contributing a Patch via GitHub. For more technical details check out our CONTRIBUTING.md file.

Getting help

To get help, first read our User Guide then check out the FAQ. If you have are having a problem then first search the issue tracker. If you don't find anything there either come to our MUC or create a new issue depending on what your problem is.

Website

URL: https://profanity-im.github.io

Repo: https://github.com/profanity-im/profanity-im.github.io

Blog

URL: https://profanity-im.github.io/blog

Repo: https://github.com/profanity-im/blog

Mailinglist

Mailing List: https://lists.posteo.de/listinfo/profanity

Chatroom

MUC: profanity@rooms.dismail.de

Plugins

Plugins repository: https://github.com/profanity-im/profanity-plugins

Description
No description provided
Readme 24 MiB
Languages
C 97.4%
Python 1.4%
Makefile 0.6%
M4 0.5%
Shell 0.1%