Module: Zxcvbn::CaseHelpers Private
- Included in:
- Matchers::Dictionary, Matchers::L33t
- Defined in:
- lib/zxcvbn/case_helpers.rb,
sig/zxcvbn/case_helpers.rbs
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Shared helper for lowercasing strings without changing their length.
Class Method Summary collapse
-
.downcase_preserving_length(string) ⇒ String
private
String#downcase can grow a string — "İ" (U+0130) downcases to "i" plus combining dot above (U+0069 U+0307).
Instance Method Summary collapse
Class Method Details
.downcase_preserving_length(string) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
String#downcase can grow a string — "İ" (U+0130) downcases to "i" plus combining dot above (U+0069 U+0307). Matchers rely on the lowercased password sharing the original's character indices, so a grown string sends out-of-range match positions to the scorer. When lengths diverge, fall back to per-character downcasing, truncating any multi-character mapping to its first character to keep positions aligned 1:1.
18 19 20 21 22 23 |
# File 'lib/zxcvbn/case_helpers.rb', line 18 def downcase_preserving_length(string) lowercased = string.downcase return lowercased if lowercased.length == string.length string.each_char.map { |char| char.downcase[0] }.join end |
Instance Method Details
#self?.downcase_preserving_length ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
3 |
# File 'sig/zxcvbn/case_helpers.rbs', line 3
def self?.downcase_preserving_length: (String string) -> String
|