Description
Preconditions
- Magento version 2.1.6 ( it doesn't matter actually )
- PHP 7.0
- Mysql 5.6
Steps to reproduce
- Add some custom options to product ( text )
- Go to product in front-end, input some emoji in that text field, e.g. "123 😍"
- Add to cart
Expected result
- Either cart would render fine or show an error that specific emoji insertion is not supported
Actual result
- The cart is empty -> https://prnt.sc/h6v033
My observations
The issues seem to be because Magento uses utf8_general_ci collation for the tables and also connection. If I try to manually insert "123 😍" in the utf8_general_ci table in the database, it doesn't allow it and shows following error:
[HY000][1366] Incorrect string value: '\xF0\x9F\x98\x8D' for column 'value' at row 1
Everything would be good if Magento wouldn't serialize ( or json_encode in the newest version ) the custom_options. ( well, not good anyway, but at least the cart would render fine, just the options would be truncated )
For example, when Magento inserts the "123 😍" in the quote_item_option.vale table, it becomes:
a:5:{i:0;s:8:"123
As you can see, the string is corrupted at the end ( it truncates the string at the place where the emoji is )
I think that even if you do not plan to switch from utf8_general_ci to some other encoding which could solve this problem, you should still try to either show an error message in the front-end for the user or at least silently remove that emoji so that at least the cart would render fine.
Let me know what you think.
Thanks.