mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-26 03:25:53 +03:00
Merge pull request #3053 from NotAFile/speedup-mxid-check
improve mxid check performance
This commit is contained in:
commit
39ce38b024
1 changed files with 4 additions and 3 deletions
|
@ -12,11 +12,11 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import string
|
||||
|
||||
from synapse.api.errors import SynapseError
|
||||
|
||||
from collections import namedtuple
|
||||
import re
|
||||
|
||||
|
||||
class Requester(namedtuple("Requester", [
|
||||
|
@ -214,7 +214,8 @@ class GroupID(DomainSpecificString):
|
|||
return group_id
|
||||
|
||||
|
||||
mxid_localpart_allowed_characters = set("_-./=" + string.ascii_lowercase + string.digits)
|
||||
# A regex that matches any valid mxid characters
|
||||
MXID_LOCALPART_REGEX = re.compile("^[_\-./=a-z0-9]*$")
|
||||
|
||||
|
||||
def contains_invalid_mxid_characters(localpart):
|
||||
|
@ -226,7 +227,7 @@ def contains_invalid_mxid_characters(localpart):
|
|||
Returns:
|
||||
bool: True if there are any naughty characters
|
||||
"""
|
||||
return any(c not in mxid_localpart_allowed_characters for c in localpart)
|
||||
return not MXID_LOCALPART_REGEX.match(localpart)
|
||||
|
||||
|
||||
class StreamToken(
|
||||
|
|
Loading…
Reference in a new issue