Skip to content

Commit

Permalink
Fix #327 - emojis no longer displaying correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
u01jmg3 committed Oct 10, 2023
1 parent 3aa4c4c commit 916ffaf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/ICal/ICal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2472,24 +2472,24 @@ protected function cleanCharacters($input)
return strtr(
$input,
array(
"\xe2\x80\x98" => "'", // ‘
"\xe2\x80\x99" => "'", // ’
"\xe2\x80\x9a" => "'", // ‚
"\xe2\x80\x9b" => "'", // ‛
"\xe2\x80\x9c" => '"', // “
"\xe2\x80\x9d" => '"', // ”
"\xe2\x80\x9e" => '"', // „
"\xe2\x80\x9f" => '"', // ‟
"\xe2\x80\x93" => '-', // –
"\xe2\x80\x94" => '--', // —
"\xe2\x80\xa6" => '...', // …
chr(145) => "'", // ‘
chr(146) => "'", // ’
chr(147) => '"', // “
chr(148) => '"', // ”
chr(150) => '-', // –
chr(151) => '--', // —
chr(133) => '...', // …
"\xe2\x80\x98" => "'", // ‘
"\xe2\x80\x99" => "'", // ’
"\xe2\x80\x9a" => "'", // ‚
"\xe2\x80\x9b" => "'", // ‛
"\xe2\x80\x9c" => '"', // “
"\xe2\x80\x9d" => '"', // ”
"\xe2\x80\x9e" => '"', // „
"\xe2\x80\x9f" => '"', // ‟
"\xe2\x80\x93" => '-', // –
"\xe2\x80\x94" => '--', // —
"\xe2\x80\xa6" => '...', // …
$this->mb_chr(145) => "'", // ‘
$this->mb_chr(146) => "'", // ’
$this->mb_chr(147) => '"', // “
$this->mb_chr(148) => '"', // ”
$this->mb_chr(150) => '-', // –
$this->mb_chr(151) => '--', // —
$this->mb_chr(133) => '...', // …
)
);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/CleanCharacterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use ICal\ICal;
use PHPUnit\Framework\TestCase;

class CleanCharacterTest extends TestCase
{
// phpcs:disable Generic.Arrays.DisallowLongArraySyntax
// phpcs:disable Squiz.Commenting.FunctionComment

protected static function getMethod($name)
{
$class = new ReflectionClass(ICal::class);
$method = $class->getMethod($name);

// < PHP 8.1.0
$method->setAccessible(true);

return $method;
}

public function testCleanCharacters()
{
$ical = new ICal();
$input = 'Test with emoji 🔴👍🏻';

self::assertSame(
self::getMethod('cleanCharacters')->invokeArgs($ical, array($input)),
$input
);
}
}

0 comments on commit 916ffaf

Please sign in to comment.