Philipp Hörist pushed to branch master at gajim / gajim
Commits:
b7d1dd12 by Philipp Hörist at 2026-03-21T09:19:13+01:00
fix: HistoryExport: Sanitize filenames
In some cases exports for MUCs could not be created because the nickname
contained chars which are not valid in a file path
- - - - -
3 changed files:
- gajim/common/helpers.py
- gajim/common/util/uri.py
- gajim/gtk/history_export.py
Changes:
=====================================
gajim/common/helpers.py
=====================================
@@ -47,6 +47,7 @@
from nbxmpp.const import ConnectionType
from nbxmpp.errors import StanzaError
from nbxmpp.namespaces import Namespace
+from nbxmpp.protocol import JID
from nbxmpp.structs import CommonError
from nbxmpp.structs import ProxyData
from qrcode.image.pil import PilImage as QrcPilImage
@@ -111,6 +112,19 @@ def sanitize_filename(filename: str) -> str:
return f'{filename}{extension}'
+def make_path_from_jid(base_path: Path, jid: JID) -> Path:
+ assert jid.domain is not None
+ domain = jid.domain[:50]
+
+ if jid.localpart is None:
+ return base_path / domain
+
+ path = base_path / domain / sanitize_filename(jid.localpart[:50])
+ if jid.resource is not None:
+ return path / sanitize_filename(jid.resource[:30])
+ return path
+
+
def generate_qr_code(content: str) -> Gdk.Texture:
qr = qrcode.QRCode(version=None,
error_correction=qrcode.constants.ERROR_CORRECT_L,
=====================================
gajim/common/util/uri.py
=====================================
@@ -280,19 +280,6 @@ def get_file_path_from_uri(uri: str) -> Path | None:
return path
-def make_path_from_jid(base_path: Path, jid: JID) -> Path:
- assert jid.domain is not None
- domain = jid.domain[:50]
-
- if jid.localpart is None:
- return base_path / domain
-
- path = base_path / domain / jid.localpart[:50]
- if jid.resource is not None:
- return path / jid.resource[:30]
- return path
-
-
def geo_provider_from_location(lat: str, lon: str) -> str:
return f"https://www.openstreetmap.org/?mlat={lat}&mlon={lon}&zoom=16"
=====================================
gajim/gtk/history_export.py
=====================================
@@ -17,12 +17,12 @@
from gajim.common import app
from gajim.common import configpaths
+from gajim.common.helpers import make_path_from_jid
from gajim.common.i18n import _
from gajim.common.modules.contacts import ResourceContact
from gajim.common.storage.archive.const import ChatDirection
from gajim.common.storage.archive.const import MessageType
from gajim.common.storage.archive.models import Message
-from gajim.common.util.uri import make_path_from_jid
from gajim.gtk.assistant import Assistant
from gajim.gtk.assistant import AssistantErrorPage
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/b7d1dd12d4b53f29a8ed97af0db49bb6a1bff4af
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/b7d1dd12d4b53f29a8ed97af0db49bb6a1bff4af
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]