From 8dba98f1e87ba79509720195beb8f85f9a207048 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sun, 8 Apr 2018 20:51:07 +0200 Subject: [PATCH] Split passphrase by selected index, not by selected word Splitting by word leads to incorrect results as soon as a word occurs more than one time in a passphrase. --- src/components/passphrase/passphraseVerifier.js | 5 ++++- src/components/passphrase/passphraseVerifier.test.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/passphrase/passphraseVerifier.js b/src/components/passphrase/passphraseVerifier.js index 752928c41..b9465a583 100644 --- a/src/components/passphrase/passphraseVerifier.js +++ b/src/components/passphrase/passphraseVerifier.js @@ -21,8 +21,11 @@ class PassphraseConfirmator extends React.Component { const words = this.props.passphrase.trim().split(/\s+/).filter(item => item.length > 0); const index = Math.floor(rand * (words.length - 1)); + const passphraseBeforeHiddenWord = words.slice(0, index).join(' '); + const passphraseAfterHiddenWord = words.slice(index + 1).join(' '); + this.setState({ - passphraseParts: this.props.passphrase.split(words[index]), + passphraseParts: [passphraseBeforeHiddenWord, passphraseAfterHiddenWord], missing: words[index], answer: '', }); diff --git a/src/components/passphrase/passphraseVerifier.test.js b/src/components/passphrase/passphraseVerifier.test.js index 09731596c..4a108aa78 100644 --- a/src/components/passphrase/passphraseVerifier.test.js +++ b/src/components/passphrase/passphraseVerifier.test.js @@ -47,9 +47,9 @@ describe('PassphraseVerifier', () => { it('should break passphrase, hide a word and show it', () => { const expectedValues = [ - 'survey stereo pool fortune oblige ', + 'survey stereo pool fortune oblige', '-----', - ' gravity goddess mistake sentence anchor pool', + 'gravity goddess mistake sentence anchor pool', ]; const spanTags = wrapper.find('.passphrase-holder span');