Skip to content

Fix bug where emojis in contrib title cause SQL error - #390

Draft
battye wants to merge 3 commits into
phpbb:3.3.xfrom
battye:fix/emojis-in-contrib-title
Draft

Fix bug where emojis in contrib title cause SQL error#390
battye wants to merge 3 commits into
phpbb:3.3.xfrom
battye:fix/emojis-in-contrib-title

Conversation

@battye

@battye battye commented Jun 10, 2024

Copy link
Copy Markdown
Member

Interesting bug that a few people have noticed @LukeWCS @Crizz0 @vinny @danieltj27 - in Titania, if you're on Windows or Android, and use an emoji like 🆕 in the new contrib name it would spit out an SQL error like Incorrect string value: '\xF0\x9F\x86\x95\x0AS...' when trying to submit. It's hard to reproduce because it seems to be fine on Mac.

My findings were that due to some code deep in Titania, unlike the other fields the actual contrib message/description seemed to be immune from this because it was being parsed to XML with the s9e text formatting library.

I've followed that lead to import s9e and parse/unparse the contrib names.

@battye
battye requested a review from Crizz0 June 10, 2024 10:40
@battye battye linked an issue Jun 10, 2024 that may be closed by this pull request
@battye
battye marked this pull request as draft June 10, 2024 11:26
@LukeWCS

LukeWCS commented Jun 10, 2024

Copy link
Copy Markdown

@battye

Trials in the test environment were successful. For both the Name and the Description field, it accepted the NEW emoji without an SQL error message.

@danieltj27

Copy link
Copy Markdown
Contributor

As a note in reference to your first post. The general error I received was when I was using Safari on macOS (latest). So it's not isolated to Windows specifically in case that's helpful to this issue.

@battye

battye commented Jun 10, 2024

Copy link
Copy Markdown
Member Author

As a note in reference to your first post. The general error I received was when I was using Safari on macOS (latest). So it's not isolated to Windows specifically in case that's helpful to this issue.

That's very interesting - I tried this quite a few times with @Crizz0 and it was erroring for him (Android) and working for me (Mac).

@danieltj27 Could you please share the precise steps you used when you saw this error on Mac? I would like to try and replicate it on my Mac... then I won't have to keep lugging out my heavy Windows laptop 😆

@danieltj27

Copy link
Copy Markdown
Contributor

@danieltj27 Could you please share the precise steps you used when you saw this error on Mac? I would like to try and replicate it on my Mac... then I won't have to keep lugging out my heavy Windows laptop 😆

I submitted a new revision of an extension on phpBB.com.

In the message text area where you can include a message to the team, I put a single thumbs up emoji: 👍.

Submitted the revision returned the error I reported.

@battye

battye commented Jun 24, 2024

Copy link
Copy Markdown
Member Author

Thanks @danieltj27, I can replicate this on my Mac now with those instructions. This is becoming quite a frustrating bug isn't it!

SQL ERROR [ mysqli ]

Incorrect string value: '\xF0\x9F\x86\x95' for column 'topic_subject' at row 1 [1366]

SQL

INSERT INTO customisation_topics (topic_id, parent_id, topic_type, topic_access, topic_category, topic_url, topic_status, topic_assigned, topic_sticky, topic_locked, topic_approved, topic_reported, topic_time, topic_posts, topic_views, topic_subject, topic_subject_clean, topic_first_post_id, topic_first_post_user_id, topic_first_post_username, topic_first_post_user_colour, topic_first_post_time, topic_last_post_id, topic_last_post_user_id, topic_last_post_username, topic_last_post_user_colour, topic_last_post_time, topic_last_post_subject, phpbb_topic_id) VALUES (0, 1, 3, 0, 8, 'a:1:{s:2:\"id\";i:1;}', 0, '', 0, 0, 1, 0, 1719208902, '', 0, 'Validation - <r>Test edit: <EMOJI seq="1f195" tseq="1f195">🆕', 'validation_r_test_edit:_emoji_seq=_1f195_tseq=_1f195_🆕', 0, 0, '', '', 1719208902, 0, 0, '', '', 1719208902, '', 0)

Could it be that the charset of the Titania tables is different than the rest of phpBB?

@DavidIQ

DavidIQ commented Apr 7, 2025

Copy link
Copy Markdown
Member

Any additional movement on this one @battye ?

@battye

battye commented Apr 13, 2025

Copy link
Copy Markdown
Member Author

My local Titania instance became FUBAR; do you @DavidIQ (or @iMattPro) have a dev phpBB+Titania database copy that you could share with me that I could restore?

@iMattPro

Copy link
Copy Markdown
Member

It might be easier simply to use utf8_encode_ucr() on the input fields.

@ECYaz

ECYaz commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Following @iMattPro's suggestion above, utf8_encode_ucr() does look like the better fit here, and it also explains the topic_subject error from June 2024. Parsing the name leaves the s9e markup in the field, so it reaches the queue topic subject as <r>Test edit: <EMOJI seq=..., and the emoji is still in there to be rejected. A character reference has neither problem, and nothing needs unparsing on the way out.

Encoding in titania_contribution::submit() rather than in the controllers covers create and edit together, and keeps the stored form out of the release topic subject, the feed and the permalink:

public function submit()
{
	// Emojis and other four byte characters are not allowed by MySQL in the
	// utf8 column the name is stored in, so replace them with their numeric
	// character reference, as core does for report text.
	$this->contrib_name = utf8_encode_ucr($this->contrib_name);

One extra bit is needed, otherwise the digits end up in the URL as cool_127381;_extension:

public function generate_permalink()
{
	$clean_name = url::generate_slug(preg_replace('/&#[0-9]+;/', '', $this->contrib_name));

Tested on a local board: creating and editing with an emoji in the name both work, the release topic subject stores fine, the permalink comes out as cool_extension, plain names and accented characters are untouched, and re-saving does not encode twice. Same approach in #439 for the attention fields, which fail the same way.

The change is on fix/contrib-name-emoji in my fork if it is useful to pull from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emojis in revision instructions cause general error

7 participants