Skip to content

Commit 4905078

Browse files
authored
Merge pull request #58 from ALanguillaume/fix-email-validation
fix: email with dashes are now considered valid
2 parents 6a7725e + d4e6435 commit 4905078

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

R/set_mail.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ attachments <- function(sg_mail, path, name, content_id) {
214214

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

221223
sg_mail_chk <- function(sg_mail) {

tests/testthat.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is part of the standard setup for testthat.
2+
# It is recommended that you do not modify it.
3+
#
4+
# Where should you do additional test configuration?
5+
# Learn more about the roles of various files in:
6+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
7+
# * https://testthat.r-lib.org/articles/special-files.html
8+
9+
library(testthat)
10+
library(sendgridr)
11+
12+
test_check("sendgridr")

tests/testthat/test-set_mail.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
test_that("Email validation works", {
2+
emails <- c(
3+
4+
5+
)
6+
expect_true(
7+
all(
8+
email_chk(emails)
9+
)
10+
)
11+
})

0 commit comments

Comments
 (0)