DAWN-294 ⁃ need a clear statement of account name business rule and a REGEX to scrub inputs
The naming restriction for account names is that they be
- Minimum of 2 characters
- Maximum of 13 characters
- First 12 characters can be "a-z" or "1-5" or "."
- 13th character can only be "a-j" or "1-5"
- Last character can't be "."
- Names of length 1 character are in some instances permitted by the code but are not encouraged as a good naming practice
The regex expression used to validate these names in the faucet form is: {code:java} (^[a-z1-5.]{1,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$) {code}
Fix is to update the regex (and the documentation on what names are allowed). The missing part of the naming rule is:
- the 13th character can only be 1-5 or a-j.
This naming restriction applies to many things, including but not limited to:
- accounts
- named permissions
- contracts
ATC The [web form HERE|https://goo.gl/forms/OHUjugUPTu7Jv1tQ2] should accept and reject, as shown, these inputs to the 'desired account name' field.
Accept:
- abc
- a.b
- .a
- booleanjulie
- tbcox123
- 1.3.5
Reject:
- .
- aa.
- booleanjulien
- tbcox456
- tbCOX
➤ Kevin Heifner commented:
- No more than 13 characters
- Last character can't be '.'
- 13th character can only be 1-5a-j (^[a-z1-5.]{1,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)
➤ Kevin Heifner commented:
[~thomas.cox] Where is this documented? I couldn't find it. [~brian.johnson] Does the faucet plugin handle this limitation?
➤ Brian Johnson commented:
You will get the same error that I believe you will get for any interface that is expecting an account_name (or any other name derived type), it will get the "name not properly normalized" exception, since the first thing that will happen is you will convert the passed in json string to an account_name. To return the "unknown key" we would have to fabricate that exception (identify the invalid account_name and then create the same "unkown key" exception since the code's plumbing wouldn't let us pass on the non-compliant account_name.
➤ Kevin Heifner commented:
[~brian.johnson] I think the way it behaves is fine. My question is does this behavior cause issues with your wallet plugin seeing how you generate suggestions?
➤ Thomas B. Cox commented:
Naming of all things (accounts, permissions, etc) follow this rule. Kevin to write a blurb.
Hat tip to Jon-Eric Cook ( @joneric ) for helping chase this down.
I have a question about the regex that dictates account names, permission names, contract names. I'm learning about it and am curious where those regex are in the code base?
➤ Brian Johnson commented:
[~kevin.heifner] It just returns the same exception listed above. [~david.atchley]'s site should be designed to anticipate other exceptions.
To accomplish the following: first char is a-z, then 1 to 11 more chars that are a-z or 1-5, and if there's a 13th char it must be a-j or 1-5
Please see the regex below: ^[a-z][a-z1-5]{1,11}[a-j1-5]?$
➤ Brian Johnson commented:
[~thomas.cox] The Description is still missing that '.' can also be used anywhere in the name, except for the last character
So can do: thomas.cox
But cannot do: thomas.cox.
The regex below includes constraints for '.'
^[a-z][a-z1-5\.]{0,10}([a-z1-5]|^\.)[a-j1-5]?$
https://regex101.com/r/tapOhh/5/tests
➤ Kevin Heifner commented:
Type name
- No more than 13 characters
- Last character can't be '.'
- 13th character can only be 1-5a-j (^[a-z1-5.]{1,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)
- account_name, permission_name, func_name are all of type name
Type type_name
- string of char up to 32 chars
Types bytes
- vector of char, limited only by vector platform limit
Type account_permission
struct account_permission {
account_name account;
permission_name permission;
};Type message
struct message {
account_name code;
func_name type;
vector<account_permission> authorization;
bytes data;
};Type account_permission_weight
struct account_permission_weight {
account_permission permission;
uint16 weight;
};Type transaction
struct transaction {
uint16 ref_block_num;
uint32 ref_block_prefix;
time expiration;
vector<account_name> scope;
vector<account_name> read_scope;
vector<message> messages;
};Type signed_transaction
struct signed_transaction : public transaction {
vector<signature> signatures;
};Type key_permission_weight
struct key_permission_weight {
public_key key;
uint16 weight;
};Type authority
struct authority {
uint32 threshold;
vector<key_permission_weight> keys;
vector<account_permission_weight> accounts;
};ABIType type_def
struct type_def {
type_name new_type_name;
type_name type;
};Type action
struct action {
name action_name;
type_name type;
};Type table
struct table {
name table_name;
type_name index_type;
vector<field_name> key_names;
vector<type_name> key_types;
type_name type;
};Type abi
struct abi {
vector<type_def> types;
vector<struct_t> structs;
vector<action> actions;
vector<table> tables;
};
➤ Thomas B. Cox commented:
I've saved the REGEX here for general reference: https://regex101.com/r/d8uKrG/1
➤ Thomas B. Cox commented:
Corey can you re-enter the form and ensure it works correctly using the NEW ATC?
Acceptance Test Criteria (ATC) testing results
Rejected
- .
- aa.
- booleanjulien
- tbcox456
- tbCOX
Accepted
- abc
- a.b
- .a
- booleanjulie
- tbcox123
- 1.3.5
Note: There is no indication of what is acceptable for the first 12 characters. Maybe the following would be an acceptable description of the naming rules.
- Minimum of 2 characters
- Maximum of 13 characters
- First 12 characters can be "a-z" or "1-5" or "."
- 13th character can only be "a-j" or "1-5"
- Last character can't be "."
Passed tests. Thanks to @joneric !
➤ Brian Johnson commented:
Sorry, [~thomas.cox], I don't know how I missed this, maybe it was the multiple attempts, but this is the regex:
(^[a-z1-5.]{0,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)[~kevin.heifner] please double check me.
So the ATC could also accept "a" and "1".
➤ Kevin Heifner commented:
[~brian.johnson] Your regex is correct.
@blockone-syncclient I think, this regex is uncorrect, because It is inpossible create account, starting from .