Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Entry fails to save when embed field contains an instagram image with emojis in the caption #22

Closed
dohayon opened this issue Feb 26, 2018 · 9 comments
Labels

Comments

@dohayon
Copy link

dohayon commented Feb 26, 2018

screenshot 2018-02-26 17 48 13

@leevigraham
Copy link
Contributor

Interesting… I'll check with @brandonkelly how craft handles emojis

@brandonkelly
Copy link
Contributor

@leevigraham Craft emoji support has 3 facets:

  • craft\helpers\StringHelper::encodeMb4() will HTML-encode all 4(+)-byte characters. Only con is that they get converted to HTML entities, which may not be desired if the string isn’t HTML.

  • LitEmoji\LitEmoji::unicodeToShortcode() will convert most emoji to :shortcodes; and shortcodeToUnicode() will convert :shortcodes: back to the unicode emjoi chars. Only con is that any unsupported emoji characters will not be touched, which could still lead to errors.

  • PostgreSQL has no trouble with emoji, so if you have a site that needs good emoji support, you should use that if at all possible instead of MySQL.

@leevigraham
Copy link
Contributor

Sounds like craft\helpers\StringHelper::encodeMb4() is the best option here given the output will always be html.

@leevigraham
Copy link
Contributor

@leevigraham
Copy link
Contributor

leevigraham commented Mar 1, 2018

Looking at the craft code it looks like fields are using encodeMb4() in the fckeditor plugin

if (Craft::$app->getDb()->getIsMysql()) {
    // Encode any 4-byte UTF-8 characters.
    $value = StringHelper::encodeMb4($value);
}

The EmbedModel implements JsonSerializable which means it's skipped by Crafts serializeValue method…

Interestingly if you try to submit an emoji in a page title then the same issue occurs:

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xF0\x9F\x98\x8Afu...' for column 'title' at row 1
The SQL being executed was: INSERT INTO `content` (`elementId`, `siteId`, `title`, `field_gender`, `field_address`, `field_email`, `field_embed`, `field_personName`, `field_telephone`, `field_telephone2`, `dateCreated`, `dateUpdated`, `uid`) VALUES (89, 1, ' 😊fun', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2018-03-01 10:27:50', '2018-03-01 10:27:50', '60cbea1b-8b6b-430f-869c-64cc95e8fd4f')

@leevigraham
Copy link
Contributor

@brandonkelly what is Craft's position on emoji support? If support is only guaranteed on a DB level then I'm tempted to follow suit.

@leevigraham
Copy link
Contributor

leevigraham commented Mar 1, 2018

@dohayon, I've implemented LitEmoji encoding / decoding. Let me know how the latest version goes

@leevigraham
Copy link
Contributor

Related: craftcms/cms#2527

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants