Version: v0.0.0-...-67e250e Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2023 License: BSD-3-Clause Imports: 4 Imported by: 18



Package user provides tools for parsing and validating user names.



This section is empty.


This section is empty.


func Clean

func Clean(userName upspin.UserName) (upspin.UserName, error)

Clean returns the user name in canonical form as described by the comments for the Parse function.

func Parse

func Parse(userName upspin.UserName) (user, suffix, domain string, err error)

Parse splits an upspin.UserName into user and domain and returns the pair. It also returns the "+" suffix part of the user name, if it has one. For example, given the user name

it would return the strings

"ann+backup" "backup" ""

Parsed validates the name as an e-mail address and lower-cases the domain so it is canonical.

The rules are:

<name> := <user name>@<domain name>

<domain name> :=

- each . separated token < 64 characters
- character set for tokens [a-z0-9\-]
- final token at least two characters
- whole name < 254 characters
- characters are case insensitive
- final period is OK, but we remove it

We ignore the rules of punycode, which is defined in .

<user name> :=

Names are validated and canonicalized by the UsernameCasePreserved profile of the RFC 7613, "Preparation, Enforcement, and Comparison of Internationalized Strings", also known as PRECIS.

Further restrictions are added here. The only ASCII punctuation characters that are legal are "!#$%&'*+-/=?^_{|}~", and a name that is only ASCII punctuation is rejected.

As a special case for use in Access and Group files, the name "*" is allowed.

Case is significant and spaces are not allowed.

The username suffix is tightly constrained: It uses the same character set as domains, but of course the spacing of periods is irrelevant.

Facebook and Google constrain usernames to [a-zA-Z0-9+-.], ignoring the period and, in Google only, ignoring everything from a plus sign onwards. We accept a superset of this but do not follow the "ignore" rules.

func ParseDomain

func ParseDomain(domain string) (string, error)

ParseDomain parses the component of a user name after the '@', that is, the domain component of an email address. The rules are defined in the documentation for Parse except the domain name itself must be less than 255 bytes long.

func ParseUser

func ParseUser(user string) (userName, suffix string, err error)

ParseUser parses the component of a user name before the '@', that is, the user component of an email address. The rules are defined in the documentation for Parse except that "*" is not a valid user and the user name itself must be less than 255 bytes long.


This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL