mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-31 12:40:28 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca90a3291e | |||
| d04083e28b | |||
| db476db25e | |||
| d37d5a361e | |||
| 5fa792ad18 | |||
| 68e418ec08 | |||
| ef615f1d74 | |||
| 563d0cdde5 | |||
| c7ab280976 | |||
| f46887bc48 |
@@ -0,0 +1,3 @@
|
||||
# Thanks!
|
||||
|
||||
github: [egulias]
|
||||
@@ -1,4 +1,5 @@
|
||||
.idea
|
||||
.vscode
|
||||
composer.lock
|
||||
report/
|
||||
vendor/
|
||||
|
||||
File diff suppressed because one or more lines are too long
+2
-1
@@ -31,7 +31,7 @@ matrix:
|
||||
|
||||
install:
|
||||
- if [ "$deps" = "low" ]; then composer update --prefer-lowest; else composer install; fi
|
||||
- if [ "$psalm" = "yes" ]; then composer require --dev vimeo/psalm; fi
|
||||
- if [ "$psalm" = "yes" ]; then composer require --dev vimeo/psalm:3.18.2; fi
|
||||
|
||||
before_script:
|
||||
- mkdir -p build/logs
|
||||
@@ -42,3 +42,4 @@ script:
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master)
|
||||
[](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
|
||||
|
||||
## Suported RFCs ##
|
||||
## Supported RFCs ##
|
||||
|
||||
This library aims to support:
|
||||
|
||||
@@ -42,16 +42,14 @@ $validator->isValid("example@example.com", new RFCValidation()); //true
|
||||
|
||||
### Available validations ###
|
||||
|
||||
1. [RFCValidation](/src/Validation/RFCValidation.php)
|
||||
2. [NoRFCWarningsValidation](/src/Validation/NoRFCWarningsValidation.php)
|
||||
3. [DNSCheckValidation](/src/Validation/DNSCheckValidation.php)
|
||||
4. [SpoofCheckValidation](/src/Validation/SpoofCheckValidation.php)
|
||||
5. [MultipleValidationWithAnd](/src/Validation/MultipleValidationWithAnd.php)
|
||||
6. [Your own validation](#how-to-extend)
|
||||
1. [RFCValidation](/src/Validation/RFCValidation.php): Standard RFC-like email validation.
|
||||
2. [NoRFCWarningsValidation](/src/Validation/NoRFCWarningsValidation.php): RFC-like validation that will fail when warnings* are found.
|
||||
3. [DNSCheckValidation](/src/Validation/DNSCheckValidation.php): Will check if there are DNS records that signal that the server accepts emails. This does not entails that the email exists.
|
||||
4. [SpoofCheckValidation](/src/Validation/SpoofCheckValidation.php): Will check for multi-utf-8 chars that can signal an erroneous email name.
|
||||
5. [MultipleValidationWithAnd](/src/Validation/MultipleValidationWithAnd.php): It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
|
||||
6. [Your own validation](#how-to-extend): You can extend the library behaviour by implementing your own validations.
|
||||
|
||||
`MultipleValidationWithAnd`
|
||||
|
||||
It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
|
||||
*warnings: Warnings are deviations from the RFC that in a broader interpretation are acceptded.
|
||||
|
||||
```php
|
||||
<?php
|
||||
@@ -66,7 +64,8 @@ $multipleValidations = new MultipleValidationWithAnd([
|
||||
new RFCValidation(),
|
||||
new DNSCheckValidation()
|
||||
]);
|
||||
$validator->isValid("example@example.com", $multipleValidations); //true
|
||||
//ietf.org has MX records signaling a server with email capabilites
|
||||
$validator->isValid("example@ietf.org", $multipleValidations); //true
|
||||
```
|
||||
|
||||
### How to extend ###
|
||||
|
||||
@@ -13,6 +13,8 @@ class EmailLexer extends AbstractLexer
|
||||
const S_BACKSLASH = 92;
|
||||
const S_DOT = 46;
|
||||
const S_DQUOTE = 34;
|
||||
const S_SQUOTE = 39;
|
||||
const S_BACKTICK = 96;
|
||||
const S_OPENPARENTHESIS = 49;
|
||||
const S_CLOSEPARENTHESIS = 261;
|
||||
const S_OPENBRACKET = 262;
|
||||
@@ -58,6 +60,8 @@ class EmailLexer extends AbstractLexer
|
||||
'/' => self::S_SLASH,
|
||||
',' => self::S_COMMA,
|
||||
'.' => self::S_DOT,
|
||||
"'" => self::S_SQUOTE,
|
||||
"`" => self::S_BACKTICK,
|
||||
'"' => self::S_DQUOTE,
|
||||
'-' => self::S_HYPHEN,
|
||||
'::' => self::S_DOUBLECOLON,
|
||||
|
||||
@@ -5,5 +5,5 @@ namespace Egulias\EmailValidator\Exception;
|
||||
class UnclosedComment extends InvalidEmail
|
||||
{
|
||||
const CODE = 146;
|
||||
const REASON = "No colosing comment token found";
|
||||
const REASON = "No closing comment token found";
|
||||
}
|
||||
|
||||
@@ -198,6 +198,9 @@ class DomainPart extends Parser
|
||||
|
||||
$domain .= $this->lexer->token['value'];
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_SP) {
|
||||
throw new CharNotAllowed();
|
||||
}
|
||||
} while (null !== $this->lexer->token['type']);
|
||||
|
||||
return $domain;
|
||||
@@ -332,6 +335,8 @@ class DomainPart extends Parser
|
||||
{
|
||||
$invalidDomainTokens = array(
|
||||
EmailLexer::S_DQUOTE => true,
|
||||
EmailLexer::S_SQUOTE => true,
|
||||
EmailLexer::S_BACKTICK => true,
|
||||
EmailLexer::S_SEMICOLON => true,
|
||||
EmailLexer::S_GREATERTHAN => true,
|
||||
EmailLexer::S_LOWERTHAN => true,
|
||||
|
||||
@@ -97,10 +97,7 @@ class DNSCheckValidation implements EmailValidation
|
||||
*/
|
||||
protected function checkDns($host)
|
||||
{
|
||||
$variant = INTL_IDNA_VARIANT_2003;
|
||||
if (defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||
$variant = INTL_IDNA_VARIANT_UTS46;
|
||||
}
|
||||
$variant = INTL_IDNA_VARIANT_UTS46;
|
||||
|
||||
$host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.';
|
||||
|
||||
@@ -118,7 +115,8 @@ class DNSCheckValidation implements EmailValidation
|
||||
private function validateDnsRecords($host)
|
||||
{
|
||||
// Get all MX, A and AAAA DNS records for host
|
||||
$dnsRecords = dns_get_record($host, DNS_MX + DNS_A + DNS_AAAA);
|
||||
// Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149
|
||||
$dnsRecords = @dns_get_record($host, DNS_MX + DNS_A + DNS_AAAA);
|
||||
|
||||
|
||||
// No MX, A or AAAA DNS records
|
||||
|
||||
@@ -138,6 +138,8 @@ class EmailLexerTests extends TestCase
|
||||
array(":", EmailLexer::S_COLON),
|
||||
array(".", EmailLexer::S_DOT),
|
||||
array("\"", EmailLexer::S_DQUOTE),
|
||||
array("'", EmailLexer::S_SQUOTE),
|
||||
array("`", EmailLexer::S_BACKTICK),
|
||||
array("-", EmailLexer::S_HYPHEN),
|
||||
array("\\", EmailLexer::S_BACKSLASH),
|
||||
array("/", EmailLexer::S_SLASH),
|
||||
|
||||
@@ -27,7 +27,7 @@ class DNSCheckValidationTest extends TestCase
|
||||
['"Fred\ Bloggs"@ietf.org'],
|
||||
['"Joe.\\Blow"@ietf.org'],
|
||||
|
||||
// unicide
|
||||
// unicode
|
||||
['ñandu.cl'],
|
||||
];
|
||||
}
|
||||
@@ -106,4 +106,4 @@ class DNSCheckValidationTest extends TestCase
|
||||
$validation->isValid("example@invalid.example.com", new EmailLexer());
|
||||
$this->assertEquals($expectedError, $validation->getError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,6 +167,9 @@ class RFCValidationTest extends TestCase
|
||||
['test@email<'],
|
||||
['test@email{'],
|
||||
['test@ '],
|
||||
['test@example.com []'],
|
||||
["test@example.com'"],
|
||||
["test@exam`ple.com"],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -211,6 +214,7 @@ class RFCValidationTest extends TestCase
|
||||
[new CRNoLF(), "example@exa\rmple.co.uk"],
|
||||
[new CRNoLF(), "example@[\r]"],
|
||||
[new CRNoLF(), "exam\rple@example.co.uk"],
|
||||
[new ExpectingATEXT(), "test@example.com'"],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user