Skip to content

Commit

Permalink
fix email check
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon committed Oct 26, 2024
1 parent 2c01f35 commit 907a71e
Show file tree
Hide file tree
Showing 4 changed files with 35 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
29 changes: 29 additions & 0 deletions spec/umbrellio_utils/checks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

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

let(:input) { "[email protected]" }

it { is_expected.to eq(true) }

context "invalid input" do
let(:input) { "invalid" }

it { is_expected.to eq(false) }
end

context "input with subdomains and digits" do
let(:input) { "[email protected]" }

it { is_expected.to eq(true) }
end

context "non-string input" do
let(:input) { 123 }

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

0 comments on commit 907a71e

Please sign in to comment.