Skip to content

Commit

Permalink
Fix email address (#479)
Browse files Browse the repository at this point in the history
Do not url encode email addresses.

Fixes #444
Fixes #434
Fixes #390
  • Loading branch information
markuspoerschke authored Dec 23, 2022
1 parent e32ed21 commit 7b9379b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `@implements IteratorAggregate<Event>` to `\Eluceo\iCal\Domain\Collection\Events`
- Added `@implements IteratorAggregate<ContentLine>` to `\Eluceo\iCal\Presentation\Component`
- Added `@return Traversable<ContentLine>` to `\Eluceo\iCal\Presentation\Component::getIterator`
- Fix EmailAddress value object: do not url encode email addresses [#479](https://github.com/markuspoerschke/iCal/pull/479)

## [2.8.0] - 2022-12-22

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/ValueObject/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public function getEmailAddress(): string

public function toUri(): Uri
{
return new Uri('mailto:' . urlencode($this->emailAddress));
return new Uri('mailto:' . $this->emailAddress);
}
}
33 changes: 33 additions & 0 deletions tests/Unit/Domain/ValueObject/EmailAddressTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the eluceo/iCal package.
*
* (c) 2022 Markus Poerschke <markus@poerschke.nrw>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Eluceo\iCal\Unit\Domain\ValueObject;

use Eluceo\iCal\Domain\ValueObject\EmailAddress;
use PHPUnit\Framework\TestCase;

class EmailAddressTest extends TestCase
{
public function testValidEmail(): void
{
$email = new EmailAddress('example@example.com');

self::assertEquals('mailto:example@example.com', $email->toUri()->getUri());
}

public function testInvalidEmail(): void
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('example@example@example.com is no valid e-mail address');

new EmailAddress('example@example@example.com');
}
}
49 changes: 24 additions & 25 deletions tests/Unit/Presentation/Factory/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function testOrganizer()

self::assertEventRendersCorrect($event, [
'ORGANIZER;CN=Test Display Name;DIR=example://directory-entry;SENT-BY=mailto',
' :sendby%40example.com:mailto:test%40example.com',
' :sendby@example.com:mailto:test@example.com',
]);
}

Expand All @@ -193,7 +193,7 @@ public function testOneAttendee()
));

self::assertEventRendersCorrect($event, [
'ATTENDEE:mailto:test%40example.com',
'ATTENDEE:mailto:test@example.com',
]);
}

Expand All @@ -208,8 +208,8 @@ public function testMultipleAttendees()
));

self::assertEventRendersCorrect($event, [
'ATTENDEE:mailto:test%40example.com',
'ATTENDEE:mailto:test2%40example.net',
'ATTENDEE:mailto:test@example.com',
'ATTENDEE:mailto:test2@example.net',
]);
}

Expand All @@ -223,7 +223,7 @@ public function testMultipleAttendees()
));
self::assertEventRendersCorrect($event, [
'ATTENDEE;CN=Test Display Name:mailto:test%40example.com',
'ATTENDEE;CN=Test Display Name:mailto:test@example.com',
]);
} */

Expand All @@ -236,7 +236,7 @@ public function testAttendeeWithIndividualCUtype()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=INDIVIDUAL:mailto:test%40example.com',
'ATTENDEE;CUTYPE=INDIVIDUAL:mailto:test@example.com',
]);
}

Expand All @@ -249,7 +249,7 @@ public function testAttendeeWithGroupCUtype()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=GROUP:mailto:test%40example.com',
'ATTENDEE;CUTYPE=GROUP:mailto:test@example.com',
]);
}

Expand All @@ -262,7 +262,7 @@ public function testAttendeeWithResourceCUtype()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=RESOURCE:mailto:test%40example.com',
'ATTENDEE;CUTYPE=RESOURCE:mailto:test@example.com',
]);
}

Expand All @@ -275,7 +275,7 @@ public function testAttendeeWithRoomCUtype()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=ROOM:mailto:test%40example.com',
'ATTENDEE;CUTYPE=ROOM:mailto:test@example.com',
]);
}

Expand All @@ -287,7 +287,7 @@ public function testAttendeeWithUnknownCUtype()
$event = (new Event())
->addAttendee($attendee);
self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=UNKNOWN:mailto:test%40example.com',
'ATTENDEE;CUTYPE=UNKNOWN:mailto:test@example.com',
]);
}

Expand All @@ -300,7 +300,7 @@ public function testAttendeeWithOneMember()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=INDIVIDUAL:mailto:test%40example.com',
'ATTENDEE;CUTYPE=INDIVIDUAL:mailto:test@example.com',
]);
}

Expand All @@ -315,8 +315,8 @@ public function testAttendeeWithMultipleMembers()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CUTYPE=INDIVIDUAL;MEMBER="mailto:test%40example.com","mailto:test%',
' 40example.net":mailto:test%40example.com',
'ATTENDEE;CUTYPE=INDIVIDUAL;MEMBER="mailto:test@example.com","mailto:test@ex',
' ample.net":mailto:test@example.com',
]);
}

Expand All @@ -329,7 +329,7 @@ public function testAttendeeWithChairRole()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;ROLE=CHAIR:mailto:test%40example.com',
'ATTENDEE;ROLE=CHAIR:mailto:test@example.com',
]);
}

Expand All @@ -344,7 +344,7 @@ public function testAttendeeWithReqParticipantRole()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;ROLE=REQ-PARTICIPANT:mailto:test%40example.com',
'ATTENDEE;ROLE=REQ-PARTICIPANT:mailto:test@example.com',
]);
}

Expand All @@ -360,7 +360,7 @@ public function testAttendeeWithParticipationStatusNeedsAction()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:test%40example.com',
'ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:test@example.com',
]);
}

Expand All @@ -376,7 +376,7 @@ public function testAttendeeWithRSVP()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;RSVP=TRUE:mailto:test%40example.com',
'ATTENDEE;RSVP=TRUE:mailto:test@example.com',
]);
}

Expand All @@ -396,8 +396,8 @@ public function testAttendeeWithDelegatedTo()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;DELEGATED-TO="mailto:jdoe%40example.com","mailto:jqpublic%40exampl',
' e.com":mailto:jsmith%40example.com',
'ATTENDEE;DELEGATED-TO="mailto:jdoe@example.com","mailto:jqpublic@example.co',
' m":mailto:jsmith@example.com',
]);
}

Expand All @@ -415,8 +415,7 @@ public function testAttendeeWithDelegatedFrom()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;DELEGATED-FROM="mailto:jsmith%40example.com":mailto:jdoe%40example',
' .com',
'ATTENDEE;DELEGATED-FROM="mailto:jsmith@example.com":mailto:jdoe@example.com',
]);
}

Expand All @@ -434,7 +433,7 @@ public function testAttendeeWithSentBy()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;SENT-BY="mailto:sray%40example.com":mailto:jdoe%40example.com',
'ATTENDEE;SENT-BY="mailto:sray@example.com":mailto:jdoe@example.com',
]);
}

Expand All @@ -450,7 +449,7 @@ public function testAttendeeWithCommonName()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;CN=Test Example:mailto:jdoe%40example.com',
'ATTENDEE;CN=Test Example:mailto:jdoe@example.com',
]);
}

Expand All @@ -467,7 +466,7 @@ public function testAttendeeWithDirectoryEntryRef()

self::assertEventRendersCorrect($event, [
'ATTENDEE;DIR="ldap://example.com:6666/o=ABC%20Industries,c=US???(cn=Jim%20D',
' olittle)":mailto:jdoe%40example.com',
' olittle)":mailto:jdoe@example.com',
]);
}

Expand All @@ -483,7 +482,7 @@ public function testAttendeeWithLanguage()
->addAttendee($attendee);

self::assertEventRendersCorrect($event, [
'ATTENDEE;LANGUAGE=en-US:mailto:jdoe%40example.com',
'ATTENDEE;LANGUAGE=en-US:mailto:jdoe@example.com',
]);
}

Expand Down

0 comments on commit 7b9379b

Please sign in to comment.