Skip to content

Commit

Permalink
Fix email check (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon authored Oct 28, 2024
1 parent 2c01f35 commit 6405165
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
umbrellio-utils (1.5.1)
umbrellio-utils (1.5.2)
memery (~> 1)

GEM
Expand Down
7 changes: 4 additions & 3 deletions lib/umbrellio_utils/checks.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

require "uri/mailto"

module UmbrellioUtils
module Checks
extend self

EMAIL_REGEXP = /\A([\w+-].?)+@[a-z\d-]+(\.[a-z]+)*\.[a-z]+\z/i
HOLDER_NAME_REGEXP = /\A([A-Za-z0-9.'-]+ ?)+\z/

def secure_compare(src, dest)
Expand All @@ -30,11 +31,11 @@ def valid_card?(number)
end

def valid_email?(email)
email.to_s =~ EMAIL_REGEXP
email.to_s.match?(URI::MailTo::EMAIL_REGEXP)
end

def valid_card_holder?(holder)
holder.to_s =~ HOLDER_NAME_REGEXP
holder.to_s.match?(HOLDER_NAME_REGEXP)
end

def valid_card_cvv?(cvv)
Expand Down
2 changes: 1 addition & 1 deletion lib/umbrellio_utils/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module UmbrellioUtils
VERSION = "1.5.1"
VERSION = "1.5.2"
end
24 changes: 24 additions & 0 deletions spec/umbrellio_utils/checks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

describe UmbrellioUtils::Checks do
describe "#valid_email?" do
subject(:result) { described_class.valid_email?(input) }

expectations = {
"[email protected]" => true,
"[email protected]" => true,
"invalid" => false,
123 => false,
nil => false,
}

expectations.each do |input, expected_result|
context "with input #{input.inspect} should return #{expected_result.inspect}" do
let(:input) { input }
let(:expected_result) { expected_result }

it { is_expected.to eq(expected_result) }
end
end
end
end

0 comments on commit 6405165

Please sign in to comment.