Skip to content

Commit

Permalink
Merge pull request #58 from ALanguillaume/fix-email-validation
Browse files Browse the repository at this point in the history
fix: email with dashes are now considered valid
  • Loading branch information
mrchypark authored Jan 3, 2024
2 parents 6a7725e + d4e6435 commit 4905078
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/set_mail.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ attachments <- function(sg_mail, path, name, content_id) {

## FIX [email protected] return TRUE
email_chk <- function(email) {
grepl("^([a-z0-9_\\.-\\+]+)@([0-9a-z\\.-]+)\\.([a-z\\.]{2,6})$",
email)
grepl(
pattern = "^[[:alnum:]._-]+@[[:alnum:].-]+$",
x = email
)
}

sg_mail_chk <- function(sg_mail) {
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(sendgridr)

test_check("sendgridr")
11 changes: 11 additions & 0 deletions tests/testthat/test-set_mail.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test_that("Email validation works", {
emails <- c(
"[email protected]",
"[email protected]"
)
expect_true(
all(
email_chk(emails)
)
)
})

0 comments on commit 4905078

Please sign in to comment.