byllyfish / precis_i18n

Python3 implementation of PRECIS framework (RFC 8264, RFC 8265, RFC 8266)
MIT License
19 stars 4 forks source link

is username actually userpart? #4

Closed hannesm closed 6 years ago

hannesm commented 6 years ago

first of all thanks for making this publicly available under a permissive license. While reading the specification (RFC8264, 8265), I came across the following definition for a username:

      username   = userpart *(1*SP userpart)
      userpart   = 1*(idpoint)

this means that a username could be foo bar. But when I try using precis_i18n in a python shell: username.enforce('foo bar'), I get: UnicodeEncodeError: 'UsernameCaseMapped' codec can't encode character '\x20' in position 3: DISALLOWED/spaces (same in the UsernameCasePreserved profile).

thus: is username actually a userpart in this library?

byllyfish commented 6 years ago

Thanks for using the library!

The "username" definition that you reference (RFC 8264, section 6.3) is not the same as the "Username Profile". Section 6.3 talks about what you might do if your application uses a non-Precis construct containing Precis elements. It would perhaps be clearer if the RFC example used "app_username" instead.

      app_username   = app_userpart *(1*SP app_userpart)
      app_userpart   = 1*(idpoint)

In this example, "app_username" is an application-layer construct: an identifier with spaces. The IdentifierClass does not allow spaces, so the RFC suggests you deal with this in your application code:

def enforce_app_username(app_username):
    profile = precis_i18n.get_profile('UsernameCasePreserved')
    userparts = [profile.enforce(userpart) for userpart in app_username.split(' ')]
    return ' '.join(userparts)

Let me know if this doesn't make sense.

hannesm commented 6 years ago

thanks for the quick reply, that makes sense!