Skip to content

Commit

Permalink
Bugfix/Default regex email not catching previous pattern (#182)
Browse files Browse the repository at this point in the history
* Updated Truemail::RegexConstant::REGEX_EMAIL_PATTERN, tests
* Updated gem development dependencies
* Updated gem version, changelog
  • Loading branch information
bestwebua authored Oct 6, 2021
1 parent 36060cd commit 5339b0e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.5.2] - 2021.10.06

### Fixed

- `Truemail::RegexConstant::REGEX_EMAIL_PATTERN` behaviour with double `@` in email. Thanks [@your-favorite-dev](https://github.com/your-favorite-dev) for bug report.

### Updated

- Updated tests
- Updated gem development dependencies
- Updated gem version

## [2.5.1] - 2021.10.01

### Updated
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
truemail (2.5.1)
truemail (2.5.2)
simpleidn (~> 0.2.1)

GEM
Expand All @@ -26,7 +26,7 @@ GEM
fasterer (0.9.0)
colorize (~> 0.7)
ruby_parser (>= 3.14.1)
ffaker (2.19.0)
ffaker (2.20.0)
hashdiff (1.0.1)
iniparse (1.5.0)
json (2.5.1)
Expand Down Expand Up @@ -70,7 +70,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.22.0)
rubocop (1.22.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
Expand Down Expand Up @@ -119,14 +119,14 @@ DEPENDENCIES
bundler-audit (~> 0.9.0.1)
dns_mock (~> 1.4, >= 1.4.2)
fasterer (~> 0.9.0)
ffaker (~> 2.19)
ffaker (~> 2.20)
json_matchers (~> 0.11.1)
overcommit (~> 0.58.0)
pry-byebug (~> 3.9)
rake (~> 13.0, >= 13.0.6)
reek (~> 6.0, >= 6.0.6)
rspec (~> 3.10)
rubocop (~> 1.22)
rubocop (~> 1.22, >= 1.22.1)
rubocop-performance (~> 1.11, >= 1.11.5)
rubocop-rspec (~> 2.5)
simplecov (~> 0.17.1)
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(arg_value, arg_name)

module RegexConstant
REGEX_DOMAIN = /[\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}/i.freeze
REGEX_EMAIL_PATTERN = /(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\W\w]*)@(#{REGEX_DOMAIN})\z)/.freeze
REGEX_EMAIL_PATTERN = %r{(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\w\p{L}.+!~,'&%#*^`{}|\-/?=$]*)@(#{REGEX_DOMAIN})\z)}.freeze
REGEX_DOMAIN_PATTERN = /(?=\A.{4,255}\z)(\A#{REGEX_DOMAIN}\z)/.freeze
REGEX_DOMAIN_FROM_EMAIL = /\A.+@(.+)\z/.freeze
REGEX_SMTP_ERROR_BODY_PATTERN = /(?=.*550)(?=.*(user|account|customer|mailbox)).*/i.freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/truemail/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Truemail
VERSION = '2.5.1'
VERSION = '2.5.2'
end
16 changes: 14 additions & 2 deletions spec/truemail/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
describe 'Truemail::RegexConstant::REGEX_EMAIL_PATTERN' do
subject(:regex_pattern) { described_class::REGEX_EMAIL_PATTERN }

let(:special_chars) { %w[- _ . + ! ~ , ' & % # $ * / = ? ^ ` { | }] }

it 'allows from 6 to 255 chars' do
expect(
regex_pattern.match?(Truemail::GenerateEmailHelper.call(size: :min))
Expand Down Expand Up @@ -67,14 +69,24 @@

it 'allows special chars' do
expect(
regex_pattern.match?(Truemail::GenerateEmailHelper.call(symbols: %w[- _ . + ! ~ , ' & % # $ * / = ? ^ ` { | }]))
regex_pattern.match?(
Truemail::GenerateEmailHelper.call(symbols: special_chars)
)
).to be(true)
end

it 'not allows special chars for one char username' do
expect(
regex_pattern.match?(
Truemail::GenerateEmailHelper.call(size: :min, invalid_email_with: %w[- _ . + ! ~ , ' & % # $ * / = ? ^ ` { | }])
Truemail::GenerateEmailHelper.call(size: :min, invalid_email_with: special_chars)
)
).to be(false)
end

it 'not allows double @ char in email' do
expect(
regex_pattern.match?(
Truemail::GenerateEmailHelper.call(invalid_email_with: %w[@])
)
).to be(false)
end
Expand Down
4 changes: 2 additions & 2 deletions truemail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler-audit', '~> 0.9.0.1'
spec.add_development_dependency 'dns_mock', '~> 1.4', '>= 1.4.2'
spec.add_development_dependency 'fasterer', '~> 0.9.0'
spec.add_development_dependency 'ffaker', '~> 2.19'
spec.add_development_dependency 'ffaker', '~> 2.20'
spec.add_development_dependency 'json_matchers', '~> 0.11.1'
spec.add_development_dependency 'overcommit', '~> 0.58.0'
spec.add_development_dependency 'pry-byebug', '~> 3.9'
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.6'
spec.add_development_dependency 'rspec', '~> 3.10'
spec.add_development_dependency 'rubocop', '~> 1.22'
spec.add_development_dependency 'rubocop', '~> 1.22', '>= 1.22.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.5'
spec.add_development_dependency 'rubocop-rspec', '~> 2.5'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
Expand Down

0 comments on commit 5339b0e

Please sign in to comment.