dictionary_component.diff 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. diff --git a/third_party/zxcvbn-cpp/data-scripts/build_frequency_lists.py b/third_party/zxcvbn-cpp/data-scripts/build_frequency_lists.py
  2. index d5504e0..9be1391 100755
  3. --- a/third_party/zxcvbn-cpp/data-scripts/build_frequency_lists.py
  4. +++ b/third_party/zxcvbn-cpp/data-scripts/build_frequency_lists.py
  5. @@ -122,8 +122,7 @@ def to_kv(lst, lst_name):
  6. val = '"%s".split(",")' % ','.join(lst)
  7. return '%s: %s' % (lst_name, val)
  8. -def output_coffee(args, script_name, freq_lists):
  9. - (output_file,) = args
  10. +def output_coffee(output_file, script_name, freq_lists):
  11. with codecs.open(output_file, 'w', 'utf8') as f:
  12. f.write('# generated by %s\n' % script_name)
  13. f.write('frequency_lists = \n ')
  14. @@ -286,6 +285,14 @@ def output_inc_js(output_file_js, script_name, freq_lists):
  15. f.write(',\n '.join(lines))
  16. f.write('}')
  17. +# Outputs the processed text files as text files again
  18. +def output_txt(output_txt, script_name, freq_lists):
  19. + for name, lst in freq_lists.items():
  20. + with codecs.open(output_txt.replace('.txt', name + '.txt'), 'w',
  21. + 'utf8') as f:
  22. + for word in lst:
  23. + f.write(word + '\n')
  24. +
  25. def main():
  26. if len(sys.argv) != 3:
  27. print(usage())
  28. @@ -301,6 +308,8 @@ def main():
  29. output_fn = output_hpp
  30. elif output_file_lower.endswith(".inc.js"):
  31. output_fn = output_inc_js
  32. + elif output_file_lower.endswith(".txt"):
  33. + output_fn = output_txt
  34. else:
  35. output_fn = output_coffee
  36. diff --git a/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.cpp b/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.cpp
  37. index 4e4b727..a7adbe9 100644
  38. --- a/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.cpp
  39. +++ b/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.cpp
  40. @@ -1,11 +1,26 @@
  41. #include <zxcvbn/frequency_lists.hpp>
  42. -#include <zxcvbn/_frequency_lists.hpp>
  43. -
  44. #include <unordered_map>
  45. +#include <utility>
  46. +
  47. +#include "base/no_destructor.h"
  48. namespace zxcvbn {
  49. +namespace {
  50. +
  51. +std::unordered_map<DictionaryTag, RankedDict>& ranked_dicts() {
  52. + static base::NoDestructor<std::unordered_map<DictionaryTag, RankedDict>>
  53. + ranked_dicts;
  54. + return *ranked_dicts;
  55. +}
  56. +
  57. +} // namespace
  58. +
  59. +void SetRankedDicts(std::unordered_map<DictionaryTag, RankedDict> dicts) {
  60. + ranked_dicts() = std::move(dicts);
  61. +}
  62. +
  63. RankedDicts convert_to_ranked_dicts(std::unordered_map<DictionaryTag, RankedDict> & ranked_dicts) {
  64. RankedDicts build;
  65. @@ -17,8 +32,7 @@ RankedDicts convert_to_ranked_dicts(std::unordered_map<DictionaryTag, RankedDict
  66. }
  67. RankedDicts default_ranked_dicts() {
  68. - return convert_to_ranked_dicts(_frequency_lists::get_default_ranked_dicts());
  69. + return convert_to_ranked_dicts(ranked_dicts());
  70. }
  71. -
  72. }
  73. diff --git a/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.hpp b/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.hpp
  74. index c75ea30..634ecb2 100644
  75. --- a/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.hpp
  76. +++ b/third_party/zxcvbn-cpp/native-src/zxcvbn/frequency_lists.hpp
  77. @@ -2,7 +2,6 @@
  78. #define __ZXCVBN__FREQUENCY_LISTS_HPP
  79. #include <zxcvbn/frequency_lists_common.hpp>
  80. -#include <zxcvbn/_frequency_lists.hpp>
  81. #include <unordered_map>
  82. @@ -10,7 +9,15 @@
  83. namespace zxcvbn {
  84. -using DictionaryTag = _frequency_lists::DictionaryTag;
  85. +enum class DictionaryTag {
  86. + ENGLISH_WIKIPEDIA,
  87. + FEMALE_NAMES,
  88. + MALE_NAMES,
  89. + PASSWORDS,
  90. + SURNAMES,
  91. + US_TV_AND_FILM,
  92. + USER_INPUTS
  93. +};
  94. }
  95. @@ -29,6 +36,8 @@ namespace zxcvbn {
  96. using RankedDicts = std::unordered_map<DictionaryTag, const RankedDict &>;
  97. +void SetRankedDicts(std::unordered_map<DictionaryTag, RankedDict> dicts);
  98. +
  99. RankedDicts convert_to_ranked_dicts(std::unordered_map<DictionaryTag, RankedDict> & ranked_dicts);
  100. RankedDicts default_ranked_dicts();