diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index fba7a400a..9fe84c3ff 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -793,9 +793,14 @@ export default class PreferencesController { if (typeof symbol !== 'string') { throw ethErrors.rpc.invalidParams(`Invalid symbol: not a string.`); } - if (!(symbol.length < 7)) { + if (!(symbol.length > 0)) { throw ethErrors.rpc.invalidParams( - `Invalid symbol "${symbol}": longer than 6 characters.`, + `Invalid symbol "${symbol}": shorter than a character.`, + ); + } + if (!(symbol.length < 12)) { + throw ethErrors.rpc.invalidParams( + `Invalid symbol "${symbol}": longer than 11 characters.`, ); } const numDecimals = parseInt(decimals, 10); diff --git a/app/scripts/controllers/preferences.test.js b/app/scripts/controllers/preferences.test.js index d7a702b6c..1c765a92b 100644 --- a/app/scripts/controllers/preferences.test.js +++ b/app/scripts/controllers/preferences.test.js @@ -539,6 +539,14 @@ describe('preferences controller', function () { decimals: 0, }), ); + assert.doesNotThrow(() => + validate({ + address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', + symbol: 'ABCDEFGHIJK', + decimals: 0, + }), + ); + assert.throws( () => validate({ symbol: 'ABC', decimals: 0 }), 'missing address should fail', @@ -563,10 +571,19 @@ describe('preferences controller', function () { () => validate({ address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', - symbol: 'ABCDEFGHI', + symbol: 'ABCDEFGHIJKLM', decimals: 0, }), - 'invalid symbol should fail', + 'long symbol should fail', + ); + assert.throws( + () => + validate({ + address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', + symbol: '', + decimals: 0, + }), + 'empty symbol should fail', ); assert.throws( () =>