q2a / question2answer

Question2Answer is a free and open source platform for Q&A sites, running on PHP/MySQL.
http://www.question2answer.org/
GNU General Public License v3.0
1.63k stars 627 forks source link

Bug: Incorrect string value for Page account when inserting Emoji #980

Open q2apro opened 1 year ago

q2apro commented 1 year ago

Replicate Bug:

  1. Edit your account
  2. Insert "Test 👍" into the Name field
  3. Save

Result:

PHP Question2Answer MySQL query error 1366: Incorrect string value: '\xF0\x9F\x91\x8D' for column 'content' at row 1 - Query: INSERT INTO qa_userprofile (userid, title, content) VALUES ('1', 'name', 'Test 👍') ON DUPLICATE KEY UPDATE content = VALUES(content)

Solution:

Probably we could clean the value in "qa-include/db/users.php":

function qa_db_user_profile_set($userid, $field, $value)

adding simply:

$value = qa_remove_utf8mb4($value);

Other solution:

The DB fields content and title are utf8mb3_general_ci. They could be altered to utf8mb4_general_ci to accept emojis. But probably for now the PHP solution is preferable.