Skip to content

Commit

Permalink
Enable UTF-8 when checking string is single line (#54)
Browse files Browse the repository at this point in the history
* Enable UTF-8 in checking single line because some multi-byte strings
contain a new line when interpreted as single byte
  • Loading branch information
frederikbosch authored Oct 30, 2018
1 parent f071a22 commit 3d38924
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class Address
*/
public function __construct(EmailAddress $address, string $name = '')
{
if (\preg_match('/\v/', $name) !== 0) {
if (\preg_match('/\v/u', $name) !== 0) {
throw new \InvalidArgumentException('Cannot use vertical white space within name of email address');
}

Expand Down
2 changes: 1 addition & 1 deletion src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class EmailAddress
*/
public function __construct(string $address)
{
if (\preg_match('/\v/', $address, $matches) !== 0) {
if (\preg_match('/\v/u', $address, $matches) !== 0) {
throw new \InvalidArgumentException('Cannot use vertical white space within email address');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Header/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Subject implements HeaderInterface
*/
public function __construct(string $subject)
{
if (\preg_match('/\v/', $subject) !== 0) {
if (\preg_match('/\v/u', $subject) !== 0) {
throw new \InvalidArgumentException('Cannot use vertical white space within subject');
}

Expand Down
9 changes: 9 additions & 0 deletions test/Unit/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public function it_can_be_converted_to_readable_string()
$this->assertEquals('local-part@münchen.com', $address->toReadableString());
}

/**
* @test
*/
public function it_can_be_constructed_with_a_multi_byte_name_leading_to_new_line_in_single_byte()
{
$address = new Address(new EmailAddress('[email protected]'), 'Миха');
$this->assertEquals('=?UTF-8?B?0JzQuNGF0LA=?= <[email protected]>', (string)$address);
}

/**
* @return array
*/
Expand Down
9 changes: 9 additions & 0 deletions test/Unit/EmailAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public function provideAddresses()
];
}

/**
* @test
*/
public function it_can_be_constructed_with_a_multi_byte_name_leading_to_new_line_in_single_byte()
{
$address = new EmailAddress('Миха@domain.com');
$this->assertEquals('Миха@domain.com', (string)$address);
}

/**
* @test
*/
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Header/BccTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
declare(strict_types=1);

namespace Genkgo\TestMail\Unit\Header;
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Header/GenericHeaderTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
declare(strict_types=1);

namespace Genkgo\TestMail\Unit\Header;
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Header/ParsedHeaderTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
declare(strict_types=1);

namespace Genkgo\TestMail\Unit\Header;
Expand Down
9 changes: 9 additions & 0 deletions test/Unit/Header/SubjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public function it_produces_correct_values($subject, $constructed, $headerName,
}
}

/**
* @test
*/
public function it_can_be_constructed_with_a_multi_byte_name_leading_to_new_line_in_single_byte()
{
$subject = new Subject('Миха');
$this->assertEquals('=?UTF-8?B?0JzQuNGF0LA=?=', (string)$subject->getValue());
}

/**
* @return array
*/
Expand Down

0 comments on commit 3d38924

Please sign in to comment.