Disallow capital letters in userids

Factor out a common function for checking user ids and group ids, which forbids
capitals.
This commit is contained in:
Richard van der Hoff 2017-10-20 23:37:22 +01:00
parent b4a6b7f720
commit 58fbbe0f1d
3 changed files with 26 additions and 17 deletions

View file

@ -12,6 +12,7 @@
# 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
@ -161,6 +162,21 @@ class GroupID(DomainSpecificString):
SIGIL = "+"
mxid_localpart_allowed_characters = set("_-./" + string.ascii_lowercase + string.digits)
def contains_invalid_mxid_characters(localpart):
"""Check for characters not allowed in an mxid or groupid localpart
Args:
localpart (basestring): the localpart to be checked
Returns:
bool: True if there are any naughty characters
"""
return any(c not in mxid_localpart_allowed_characters for c in localpart)
class StreamToken(
namedtuple("Token", (
"room_key",