Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 1... Zeile 1...
1
<?php
1
<?php
-
 
2
 
2
namespace Egulias\EmailValidator\Parser;
3
namespace Egulias\EmailValidator\Parser;
Zeile 3... Zeile 4...
3
 
4
 
4
use Egulias\EmailValidator\EmailLexer;
5
use Egulias\EmailValidator\EmailLexer;
5
use Egulias\EmailValidator\Result\ValidEmail;
6
use Egulias\EmailValidator\Result\ValidEmail;
Zeile 10... Zeile 11...
10
use Egulias\EmailValidator\Result\Reason\UnclosedQuotedString;
11
use Egulias\EmailValidator\Result\Reason\UnclosedQuotedString;
11
use Egulias\EmailValidator\Result\Result;
12
use Egulias\EmailValidator\Result\Result;
Zeile 12... Zeile 13...
12
 
13
 
13
class DoubleQuote extends PartParser
14
class DoubleQuote extends PartParser
14
{
15
{
15
    public function parse() : Result
16
    public function parse(): Result
Zeile 16... Zeile 17...
16
    {
17
    {
17
 
18
 
Zeile 18... Zeile 19...
18
        $validQuotedString = $this->checkDQUOTE();
19
        $validQuotedString = $this->checkDQUOTE();
19
        if($validQuotedString->isInvalid()) return $validQuotedString;
20
        if ($validQuotedString->isInvalid()) return $validQuotedString;
20
 
21
 
21
        $special = [
22
        $special = [
Zeile 28... Zeile 29...
28
            EmailLexer::C_NUL => true,
29
            EmailLexer::C_NUL => true,
29
            EmailLexer::S_HTAB => true,
30
            EmailLexer::S_HTAB => true,
30
            EmailLexer::S_CR => true,
31
            EmailLexer::S_CR => true,
31
            EmailLexer::S_LF => true
32
            EmailLexer::S_LF => true
32
        ];
33
        ];
33
        
34
 
34
        $setSpecialsWarning = true;
35
        $setSpecialsWarning = true;
Zeile 35... Zeile 36...
35
 
36
 
Zeile 36... Zeile 37...
36
        $this->lexer->moveNext();
37
        $this->lexer->moveNext();
37
 
38
 
38
        while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) {
39
        while (!$this->lexer->current->isA(EmailLexer::S_DQUOTE) && !$this->lexer->current->isA(EmailLexer::S_EMPTY)) {
39
            if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
40
            if (isset($special[$this->lexer->current->type]) && $setSpecialsWarning) {
40
                $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
41
                $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
41
                $setSpecialsWarning = false;
42
                $setSpecialsWarning = false;
42
            }
43
            }
43
            if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
44
            if ($this->lexer->current->isA(EmailLexer::S_BACKSLASH) && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
Zeile 44... Zeile 45...
44
                $this->lexer->moveNext();
45
                $this->lexer->moveNext();
Zeile 45... Zeile 46...
45
            }
46
            }
46
 
47
 
47
            $this->lexer->moveNext();
48
            $this->lexer->moveNext();
48
 
49
 
Zeile 49... Zeile 50...
49
            if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
50
            if (!$this->escaped() && isset($invalid[$this->lexer->current->type])) {
Zeile 50... Zeile 51...
50
                return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']);
51
                return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->current->value);
51
            }
52
            }
52
        }
53
        }
53
 
54
 
Zeile 54... Zeile 55...
54
        $prev = $this->lexer->getPrevious();
55
        $prev = $this->lexer->getPrevious();
55
 
56
 
56
        if ($prev['type'] === EmailLexer::S_BACKSLASH) {
57
        if ($prev->isA(EmailLexer::S_BACKSLASH)) {
Zeile 57... Zeile 58...
57
            $validQuotedString = $this->checkDQUOTE();
58
            $validQuotedString = $this->checkDQUOTE();
58
            if($validQuotedString->isInvalid()) return $validQuotedString;
59
            if ($validQuotedString->isInvalid()) return $validQuotedString;
Zeile 59... Zeile 60...
59
        }
60
        }
60
 
61
 
61
        if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
62
        if (!$this->lexer->isNextToken(EmailLexer::S_AT) && !$prev->isA(EmailLexer::S_BACKSLASH)) {
Zeile 62... Zeile 63...
62
            return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']);
63
            return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->current->value);
63
        }
64
        }
64
 
65
 
65
        return new ValidEmail();
66
        return new ValidEmail();
Zeile 66... Zeile 67...
66
    }
67
    }
67
 
68
 
68
    protected function checkDQUOTE() : Result
69
    protected function checkDQUOTE(): Result
69
    {
70
    {
70
        $previous = $this->lexer->getPrevious();
71
        $previous = $this->lexer->getPrevious();
71
 
72
 
Zeile 72... Zeile 73...
72
        if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
73
        if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous->isA(EmailLexer::GENERIC)) {
73
            $description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit';
74
            $description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit';
74
            return new InvalidEmail(new ExpectingATEXT($description), $this->lexer->token['value']);
-
 
75
        }
75
            return new InvalidEmail(new ExpectingATEXT($description), $this->lexer->current->value);