Skip to content

Commit

Permalink
Technical/Update default regex email pattern (#160)
Browse files Browse the repository at this point in the history
* Updated Truemail::RegexConstant::REGEX_EMAIL_PATTERN, tests
* Updated gem development dependencies
* Updated Rubocop/Codeclimate config
* Updated gem version, changelog
  • Loading branch information
bestwebua authored Jun 29, 2021
1 parent 2f80d9f commit 1439d71
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ checks:
plugins:
rubocop:
enabled: true
channel: rubocop-1-16
channel: rubocop-1-18

reek:
enabled: true
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Naming/VariableNumber:
Naming/RescuedExceptionsVariableName:
Enabled: false

Naming/InclusiveLanguage:
Enabled: false

Style/Documentation:
Enabled: false

Expand Down Expand Up @@ -197,6 +200,9 @@ Layout/BeginEndAlignment:
Layout/SpaceBeforeBrackets:
Enabled: true

Layout/LineEndStringConcatenationIndentation:
Enabled: true

Lint/NonDeterministicRequireOrder:
Enabled: false

Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

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.4.4] - 2021.06.29

### Updated

Allowed using special characters in email user names (following [RFC 3696](https://datatracker.ietf.org/doc/html/rfc3696#page-6)) for default regex email pattern.

- Updated `Truemail::RegexConstant::REGEX_EMAIL_PATTERN`, tests
- Updated gem development dependencies
- Updated Rubocop/Codeclimate config
- Updated gem documentation, version

## [2.4.3] - 2021.06.15

### 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.4.3)
truemail (2.4.4)
simpleidn (~> 0.2.1)

GEM
Expand Down Expand Up @@ -75,7 +75,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.16.1)
rubocop (1.18.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
Expand Down Expand Up @@ -121,7 +121,7 @@ PLATFORMS
x86_64-darwin-20

DEPENDENCIES
bundler (~> 2.2, >= 2.2.20)
bundler (~> 2.2, >= 2.2.21)
bundler-audit (~> 0.8.0)
dns_mock (~> 1.3)
faker (~> 2.18)
Expand All @@ -132,7 +132,7 @@ DEPENDENCIES
rake (~> 13.0, >= 13.0.3)
reek (~> 6.0, >= 6.0.4)
rspec (~> 3.10)
rubocop (~> 1.16, >= 1.16.1)
rubocop (~> 1.18)
rubocop-performance (~> 1.11, >= 1.11.3)
rubocop-rspec (~> 2.4)
simplecov (~> 0.17.1)
Expand All @@ -141,4 +141,4 @@ DEPENDENCIES
webmock (~> 3.13)

BUNDLED WITH
2.2.20
2.2.21
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|\-.+]*)@(#{REGEX_DOMAIN})\z)/.freeze
REGEX_EMAIL_PATTERN = /(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\W\w]*)@(#{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.4.3'
VERSION = '2.4.4'
end
18 changes: 13 additions & 5 deletions spec/truemail/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@
end
end

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

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

Expand All @@ -82,6 +84,12 @@
expect(regex_pattern.match?(email_example)).to be(true)
end
end

it 'allows not ascii chars in user and domain with special characters in user name' do
%w[niña+mañana@mañana.cØm квіточка!@пошта.укр user~Admin@納豆.jp].each do |email_example|
expect(regex_pattern.match?(email_example)).to be(true)
end
end
end

describe 'Truemail::RegexConstant::REGEX_DOMAIN_PATTERN' do
Expand Down
4 changes: 2 additions & 2 deletions truemail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency 'simpleidn', '~> 0.2.1'

spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.20'
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.21'
spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
spec.add_development_dependency 'dns_mock', '~> 1.3'
spec.add_development_dependency 'faker', '~> 2.18'
Expand All @@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
spec.add_development_dependency 'rspec', '~> 3.10'
spec.add_development_dependency 'rubocop', '~> 1.16', '>= 1.16.1'
spec.add_development_dependency 'rubocop', '~> 1.18'
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
Expand Down

0 comments on commit 1439d71

Please sign in to comment.