From: Coleman Watts Date: Thu, 25 Aug 2016 02:36:02 +0000 (-0400) Subject: CRM_Utils_ICalendar cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=046dd6c2382ccd0c71022deaf3d80605180363cb;p=civicrm-core.git CRM_Utils_ICalendar cleanup --- diff --git a/CRM/Utils/ICalendar.php b/CRM/Utils/ICalendar.php index d765b80f84..5784ed9cbf 100644 --- a/CRM/Utils/ICalendar.php +++ b/CRM/Utils/ICalendar.php @@ -42,23 +42,39 @@ class CRM_Utils_ICalendar { /** * Escape text elements for safe ICalendar use. * - * @param $text + * @param string $text * Text to escape. * * @return string - * Escaped text */ public static function formatText($text) { $text = strip_tags($text); $text = str_replace("\"", "DQUOTE", $text); $text = str_replace("\\", "\\\\", $text); - $text = str_replace(",", "\,", $text); - $text = str_replace(";", "\;", $text); + $text = str_replace(',', '\,', $text); + $text = str_replace(';', '\;', $text); $text = str_replace(array("\r\n", "\n", "\r"), "\\n ", $text); $text = implode("\n ", str_split($text, 50)); return $text; } + /** + * Restore iCal formatted text to normal. + * + * @param string $text + * Text to unescape. + * + * @return string + */ + public static function unformatText($text) { + $text = str_replace('\n ', "\n", $text); + $text = str_replace('\;', ';', $text); + $text = str_replace('\,', ',', $text); + $text = str_replace("\\\\", "\\", $text); + $text = str_replace("DQUOTE", "\"", $text); + return $text; + } + /** * Escape date elements for safe ICalendar use. * diff --git a/tests/phpunit/CRM/Utils/ICalendarTest.php b/tests/phpunit/CRM/Utils/ICalendarTest.php new file mode 100644 index 0000000000..e2f45d2fd5 --- /dev/null +++ b/tests/phpunit/CRM/Utils/ICalendarTest.php @@ -0,0 +1,55 @@ +assertEquals($testString, CRM_Utils_ICalendar::unformatText(CRM_Utils_ICalendar::formatText($testString))); + } + +}