Skip to content

Commit

Permalink
Handle importing whitespace-only seed phrases
Browse files Browse the repository at this point in the history
Fixes MetaMask#6694

This changeset fixes our parsing of seed phrases during import to handle the
case where a user tries to import a seed phrase that consists solely of whitespace.
We no longer produce an error and instead treat it as an incorrect seed phrase.
  • Loading branch information
whymarrh committed Jun 26, 2019
1 parent aa7ba76 commit 017a7e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ export default class ImportWithSeedPhrase extends PureComponent {
}

parseSeedPhrase = (seedPhrase) => {
return seedPhrase
.trim()
.match(/\w+/g)
.join(' ')
const trimmed = seedPhrase.trim()
if (!trimmed) {
return ''
}

return trimmed.match(/\w+/g).join(' ')
}

componentWillMount () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@ describe('ImportWithSeedPhrase Component', () => {

assert.deepEqual(parseSeedPhrase(' foo bar baz '), 'foo bar baz')
})

it('should return an empty string when given a whitespace-only string', () => {
const root = shallowRender({
onSubmit: sinon.spy(),
})

const {parseSeedPhrase} = root.instance()

assert.deepEqual(parseSeedPhrase(' '), '')
})
})
})

0 comments on commit 017a7e1

Please sign in to comment.