Skip to content

Can't save emoji in custom product options #12058

Closed
@archonkulis

Description

@archonkulis

Preconditions

  1. Magento version 2.1.6 ( it doesn't matter actually )
  2. PHP 7.0
  1. Mysql 5.6

Steps to reproduce

  1. Add some custom options to product ( text )
  2. Go to product in front-end, input some emoji in that text field, e.g. "123 😍"
  3. Add to cart

Expected result

  1. Either cart would render fine or show an error that specific emoji insertion is not supported

Actual result

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions