(botchy) fix for emoticons in event description

This commit is contained in:
JodliDev 2021-09-30 07:01:11 +02:00
parent 72dd4dffcd
commit 72e7983d75
3 changed files with 22 additions and 10 deletions

View file

@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS `caldav_calendars` (
`calendar_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
`source_id` int(10) UNSIGNED DEFAULT NULL,
`name` varchar(255) NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
`color` varchar(8) NOT NULL,
`showalarms` tinyint(1) NOT NULL DEFAULT '1',
@ -55,7 +55,7 @@ CREATE TABLE IF NOT EXISTS `caldav_calendars` (
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_caldav_calendars_sources` FOREIGN KEY (`source_id`)
REFERENCES `caldav_sources`(`source_id`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
CREATE TABLE IF NOT EXISTS `caldav_events` (
`event_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
@ -70,10 +70,10 @@ CREATE TABLE IF NOT EXISTS `caldav_events` (
`start` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
`end` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
`recurrence` varchar(255) DEFAULT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`location` varchar(255) NOT NULL DEFAULT '',
`categories` varchar(255) NOT NULL DEFAULT '',
`title` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
`description` text CHARACTER SET utf8mb4 NOT NULL,
`location` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
`categories` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
`url` varchar(255) NOT NULL DEFAULT '',
`all_day` tinyint(1) NOT NULL DEFAULT '0',
`free_busy` tinyint(1) NOT NULL DEFAULT '0',
@ -94,7 +94,7 @@ CREATE TABLE IF NOT EXISTS `caldav_events` (
INDEX `caldav_calendar_notify_idx` (`calendar_id`,`notifyat`),
CONSTRAINT `fk_caldav_events_calendar_id` FOREIGN KEY (`calendar_id`)
REFERENCES `caldav_calendars`(`calendar_id`) ON DELETE CASCADE ON UPDATE CASCADE
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
CREATE TABLE IF NOT EXISTS `caldav_attachments` (
`attachment_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,

View file

@ -502,6 +502,11 @@ class caldav_driver extends calendar_driver
{
//$event = $this->_save_preprocess($event);
//TODO: proper 4 byte character (eg emoticons) handling
//utf8 in mysql only supports 3 byte characters, so this throws an error if there are emoticons in the description.
//For now we just remove them. But instead of removing, we should prepare the database for them (by using utf8mb4)
$desc = preg_replace('/[\xF0-\xF7].../s', '', strval($event['description']));
$this->rc->db->query(sprintf(
"INSERT INTO " . $this->db_events . "
(calendar_id, created, changed, uid, recurrence_id, instance, isexception, %s, %s, all_day, recurrence,
@ -523,7 +528,7 @@ class caldav_driver extends calendar_driver
intval($event['all_day']),
$event['_recurrence'],
strval($event['title']),
strval($event['description']),
$desc,
strval($event['location']),
join(',', (array)$event['categories']),
strval($event['url']),
@ -940,8 +945,13 @@ class caldav_driver extends calendar_driver
$sql_set[] = $this->rc->db->quote_identifier($col) . '=' . $this->rc->db->quote($event[$col]->format(self::DB_DATE_FORMAT));
else if (is_array($event[$col]))
$sql_set[] = $this->rc->db->quote_identifier($col) . '=' . $this->rc->db->quote(join(',', $event[$col]));
else if (array_key_exists($col, $event))
$sql_set[] = $this->rc->db->quote_identifier($col) . '=' . $this->rc->db->quote($event[$col]);
else if (array_key_exists($col, $event)) {
//TODO: proper 4 byte character (eg emoticons) handling
//utf8 in mysql only supports 3 byte characters, so this throws an error if there are emoticons in the description.
//For now we just remove them. But instead of removing, we should prepare the database for them (by using utf8mb4)
$text = preg_replace('/[\xF0-\xF7].../s', '', $event[$col]);
$sql_set[] = $this->rc->db->quote_identifier($col) . '=' . $this->rc->db->quote($text);
}
}
if ($event['_recurrence'])

View file

@ -715,6 +715,8 @@ class database_driver extends calendar_driver
'title', 'description', 'location', 'categories', 'url', 'free_busy', 'priority',
'sensitivity', 'status', 'attendees', 'alarms', 'notifyat'
);
if(array_key_exists('notifyat', $event) && empty($event['notifyat']))
unset($event['notifyat']);
foreach ($set_cols as $col) {
if (!empty($event[$col]) && is_a($event[$col], 'DateTime')) {