Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
269a91a4 by Philipp Hörist at 2025-03-01T20:01:34+01:00
fix: JID: Raise error on IRIs with auth component
- - - - -
3 changed files:
- nbxmpp/protocol.py
- nbxmpp/xmppiri.py
- test/unit/test_jid_parsing.py
Changes:
=====================================
nbxmpp/protocol.py
=====================================
@@ -787,7 +787,11 @@ class JID:
@classmethod
@functools.cache
def from_iri(cls, iri_str: str, *, force_bare: bool = False) -> JID:
- iri_str = clean_iri(iri_str)
+ try:
+ iri_str = clean_iri(iri_str)
+ except ValueError as error:
+ raise InvalidJid('Unable to parse "%s"' % iri_str) from error
+
localpart, domainpart, resourcepart = split_jid_string(iri_str)
if localpart is not None:
=====================================
nbxmpp/xmppiri.py
=====================================
@@ -123,9 +123,7 @@ def clean_iri(iri_str: str) -> str:
iri_str = iri_str.removeprefix("xmpp:")
if iri_str.startswith("//"):
- # Remove auth component
- iri_str = iri_str.removeprefix("//")
- iri_str = iri_str.split("/", maxsplit=1)[1]
+ raise ValueError("IRI with auth component is unsupported")
# Remove query and fragment
iri_str = iri_str.split("?", maxsplit=1)[0]
=====================================
test/unit/test_jid_parsing.py
=====================================
@@ -244,6 +244,17 @@ class JIDParsing(unittest.TestCase):
parsed_jid = JID.from_iri(iri_string)
self.assertEqual(str(parsed_jid), jid_string)
+ raise_tests = [
+ "xmpp://[email protected]",
+ "xmpp://[email protected]/test",
+ "xmpp:/[email protected]/[email protected]",
+ "xmpp:/[email protected]/test",
+ ]
+
+ for iri_string in raise_tests:
+ with self.assertRaises(InvalidJid):
+ JID.from_iri(iri_string)
+
def test_compare_jid(self):
jid1 = JID(localpart="test", domain="test.com", resource="test")
jid2 = JID(localpart="test", domain="test.com", resource="test")
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/269a91a41f0b6095becec4d3168e72d5d2229736
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/269a91a41f0b6095becec4d3168e72d5d2229736
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]