lib/faker/default/internet.rb in faker-2.22.0 vs lib/faker/default/internet.rb in faker-2.23.0

- old
+ new

@@ -172,10 +172,12 @@ keywords << :max_length if legacy_max_length != NOT_GIVEN keywords << :mix_case if legacy_mix_case != NOT_GIVEN keywords << :special_characters if legacy_special_characters != NOT_GIVEN end + raise ArgumentError, 'Password of length 1 can not have both mixed case and special characters' if min_length <= 1 && mix_case && special_characters + min_alpha = mix_case && min_length > 1 ? 2 : 0 temp = Lorem.characters(number: min_length, min_alpha: min_alpha) diff_length = max_length - min_length if diff_length.positive? @@ -198,10 +200,12 @@ rand(1..min_length).times do |i| temp[i] = chars[rand(chars.length)] end end + temp[rand(temp.size - 1)] = Lorem.characters(number: 1, min_alpha: 1).upcase if mix_case && special_characters && !temp.match(/[A-z]+/) + temp end # rubocop:enable Metrics/ParameterLists ## @@ -264,11 +268,11 @@ # @return [String] # # @example # Faker::Internet.domain_word #=> "senger" def domain_word - with_locale(:en) { Char.prepare(Company.name.split(' ').first) } + with_locale(:en) { Char.prepare(Company.name.split.first) } end ## Returns the domain suffix e.g. com, org, co, biz, info etc. # # @return [String] @@ -607,13 +611,13 @@ def sanitize_email_local_part(local_part) char_range = [ Array('0'..'9'), Array('A'..'Z'), Array('a'..'z'), - "!#$%&'*+-/=?^_`{|}~.".split(//) + "!#$%&'*+-/=?^_`{|}~.".chars ].flatten - local_part.split(//).map do |char| + local_part.chars.map do |char| char_range.include?(char) ? char : '#' end.join end def construct_email(local_part, domain_name)