Copyleft Games

Improve GCI username escaping

Currently when a student completes comment verification for their GCI username is converted to a site username by the following rules: Letters a-z are kept as-is Letters A-Z are converted to lowercase Everything else is changed to underscore

The exact code for this is as follows: def getitem(self, code):

    # pass through lowercase
    if code > 96 and code < 123:
        return code
    # convert to lowercase
    if code > 64 and code < 91:
        return code+32
    # default to underscore
    return 95

This was a quick and dirty solution that works, but also generates usernames such as george_whitegeorgewhite, austin__, and v_ca_clavc__a_raier.

Usernames are not technically limited to simply a-z and underscore though, the full list of legal username characters is detailed in also provides some guidelines for how to escape illegal characters for usernames.

Write a replacement getitem method to generate legal XMPP JIDs according to XEP-0106 and attach it to this task. Also include a few unit tests to demonstrate this doing what you intend.

Task tags

  • python
  • xmpp

Students who completed this task

Václav Šraier

Task type

  • code Code
  • done_all Quality Assurance