Skip to content

Commit f321026

Browse files
authored
Merge branch 'master' into feature/fix-thread-safety
2 parents 97f3971 + d46c84e commit f321026

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

tests/zxcvbn_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ def test_empty_password():
4646
zxcvbn(password, user_inputs=[input_])
4747
except IndexError as ie:
4848
assert False, "Empty password raised IndexError"
49+
50+
51+
def test_user_inputs_side_effects():
52+
password = '7r3iz3|)0uz3'
53+
input_ = [password]
54+
55+
guess1 = zxcvbn(password)['guesses_log10']
56+
zxcvbn('somepassword', user_inputs=input_)
57+
guess2 = zxcvbn(password)['guesses_log10']
58+
assert abs(guess1 - guess2) < 1

zxcvbn/matching.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from . import adjacency_graphs
33
import re
44
import functools
5+
import copy
56

67
from zxcvbn.scoring import most_guessable_match_sequence
78

@@ -40,6 +41,12 @@ def wrapper(*args, **kwargs):
4041
return wrapper
4142

4243

44+
@ensure_ranked_dictionaries
45+
def add_frequency_lists(frequency_lists_, *, _ranked_dictionaries):
46+
for name, lst in frequency_lists_.items():
47+
_ranked_dictionaries[name] = build_ranked_dict(lst)
48+
49+
4350
GRAPHS = {
4451
'qwerty': adjacency_graphs.ADJACENCY_GRAPHS['qwerty'],
4552
'dvorak': adjacency_graphs.ADJACENCY_GRAPHS['dvorak'],
@@ -98,7 +105,8 @@ def wrapper(*args, **kwargs):
98105
# omnimatch -- perform all matches
99106
@ensure_ranked_dictionaries
100107
def omnimatch(password, _ranked_dictionaries=None, user_inputs=[]):
101-
if len(user_inputs):
108+
if _ranked_dictionaries is not None and user_inputs:
109+
_ranked_dictionaries = copy.copy(_ranked_dictionaries)
102110
_ranked_dictionaries['user_inputs'] = build_ranked_dict(user_inputs)
103111

104112
matches = []

0 commit comments

Comments
 (0)