зеркало из https://github.com/mozilla/pjs.git
Bug 620593: add normalizeAccount, use in addon UI. r=philiKON
This commit is contained in:
Родитель
9374404bfe
Коммит
4446c521f0
|
@ -1249,6 +1249,12 @@ let Utils = {
|
|||
return Utils.encodeKeyBase32(Utils.generateRandomBytes(16));
|
||||
},
|
||||
|
||||
trim: function trim(s) {
|
||||
if (s)
|
||||
return s.replace(/^\s+/, "").replace(/\s+$/, "");
|
||||
return s;
|
||||
},
|
||||
|
||||
/**
|
||||
* The following are the methods supported for UI use:
|
||||
*
|
||||
|
@ -1264,6 +1270,8 @@ let Utils = {
|
|||
* take a presentable passphrase and reduce it to a normalized
|
||||
* representation for storage. normalizePassphrase can safely be called
|
||||
* on normalized input.
|
||||
* * normalizeAccount:
|
||||
* take user input for account/username, cleaning up appropriately.
|
||||
*/
|
||||
|
||||
isPassphrase: function(s) {
|
||||
|
@ -1310,7 +1318,7 @@ let Utils = {
|
|||
normalizePassphrase: function normalizePassphrase(pp) {
|
||||
// Short var name... have you seen the lines below?!
|
||||
// Allow leading and trailing whitespace.
|
||||
pp = pp.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "");
|
||||
pp = Utils.trim(pp.toLowerCase());
|
||||
|
||||
// 20-char sync key.
|
||||
if (pp.length == 23 &&
|
||||
|
@ -1332,6 +1340,10 @@ let Utils = {
|
|||
// Something else -- just return.
|
||||
return pp;
|
||||
},
|
||||
|
||||
normalizeAccount: function normalizeAccount(acc) {
|
||||
return Utils.trim(acc);
|
||||
},
|
||||
|
||||
// WeaveCrypto returns bad base64 strings. Truncate excess padding
|
||||
// and decode.
|
||||
|
|
|
@ -82,4 +82,8 @@ function run_test() {
|
|||
do_check_eq(Utils.passphraseStrength("1"), 10);
|
||||
do_check_eq(Utils.passphraseStrength("12"), 12);
|
||||
do_check_eq(Utils.passphraseStrength("a1"), 12);
|
||||
|
||||
_("Normalizing username.");
|
||||
do_check_eq(Utils.normalizeAccount(" QA1234+boo@mozilla.com "), "QA1234+boo@mozilla.com");
|
||||
do_check_eq(Utils.normalizeAccount("QA1234+boo@mozilla.com"), "QA1234+boo@mozilla.com");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче