Commit 1cc53fba authored by Philipp Hörist's avatar Philipp Hörist
Browse files

change: Use stringprep instead of precis for JID validation

NOTES: You can set the env variable NBXMPP_USE_PRECIS to revert back
to the old behavior.
parent 4c09587d
Pipeline #10838 passed with stages
in 1 minute
......@@ -25,6 +25,7 @@ from typing import Union
from typing import Optional
from typing import cast
import os
import time
import hashlib
import functools
......@@ -39,10 +40,14 @@ import idna
from precis_i18n import get_profile
from nbxmpp.simplexml import Node
from nbxmpp.namespaces import Namespace
from nbxmpp.stringprep import nodeprep
from nbxmpp.stringprep import resourceprep
def ascii_upper(s):
return s.upper()
......@@ -482,6 +487,12 @@ def validate_localpart(localpart: str) -> str:
if not localpart or len(localpart.encode()) > 1023:
raise LocalpartByteLimit
if os.environ.get('NBXMPP_USE_PRECIS') is None:
return nodeprep(localpart)
except Exception:
raise LocalpartNotAllowedChar
if _localpart_disallowed_chars & set(localpart):
raise LocalpartNotAllowedChar
......@@ -497,6 +508,12 @@ def validate_resourcepart(resourcepart: str) -> str:
if not resourcepart or len(resourcepart.encode()) > 1023:
raise ResourcepartByteLimit
if os.environ.get('NBXMPP_USE_PRECIS') is None:
return resourceprep(resourcepart)
except Exception:
raise ResourcepartNotAllowedChar
opaque = get_profile('OpaqueString')
return opaque.enforce(resourcepart)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment