Skip to content

Commit d42c873

Browse files
authored
Fix issue that local part parser uses remaining code from lexer (#409)
Without this fix the added test will output 1) Egulias\EmailValidator\Tests\EmailValidator\EmailParserTest::testMultipleEmailAddresses Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'another-local-part' +'some-random-but-large-domain-part.example.comanother-local-part'
1 parent 5153460 commit d42c873

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Parser/LocalPart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class LocalPart extends PartParser
3434

3535
public function parse(): Result
3636
{
37+
$this->lexer->clearRecorded();
3738
$this->lexer->startRecording();
3839

3940
while (!$this->lexer->current->isA(EmailLexer::S_AT) && !$this->lexer->current->isA(EmailLexer::S_EMPTY)) {

tests/EmailValidator/EmailParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,18 @@ public function testGetParts($email, $local, $domain)
2828
$this->assertEquals($local, $parser->getLocalPart());
2929
$this->assertEquals($domain, $parser->getDomainPart());
3030
}
31+
32+
public function testMultipleEmailAddresses()
33+
{
34+
$parser = new EmailParser(new EmailLexer());
35+
$parser->parse('[email protected]');
36+
37+
$this->assertSame('some-local-part', $parser->getLocalPart());
38+
$this->assertSame('some-random-but-large-domain-part.example.com', $parser->getDomainPart());
39+
40+
$parser->parse('[email protected]');
41+
42+
$this->assertSame('another-local-part', $parser->getLocalPart());
43+
$this->assertSame('another.example.com', $parser->getDomainPart());
44+
}
3145
}

0 commit comments

Comments
 (0)