diff options
-rw-r--r-- | phpBB/includes/message_parser.php | 9 | ||||
-rw-r--r-- | phpBB/language/en/posting.php | 2 | ||||
-rw-r--r-- | phpBB/posting.php | 8 | ||||
-rw-r--r-- | tests/functional/posting_test.php | 23 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 10 |
5 files changed, 51 insertions, 1 deletions
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 6d3907880e..9d95620e0f 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1194,6 +1194,15 @@ class parse_message extends bbcode_firstpass } } + // Check for out-of-bounds characters that are currently + // not supported by utf8_bin in MySQL + if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $this->message, $matches)) + { + $character_list = implode('<br />', $matches[0]); + $this->warn_msg[] = $user->lang('UNSUPPORTED_CHARACTERS_MESSAGE', $character_list); + return $update_this_message ? $this->warn_msg : $return_message; + } + // Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length. // The maximum length check happened before any parsings. if ($mode === 'post' && utf8_clean_string($this->message) === '') diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index 20377287fd..e8a8643cfd 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -256,6 +256,8 @@ $lang = array_merge($lang, array( 'UNAUTHORISED_BBCODE' => 'You cannot use certain BBCodes: %s.', 'UNGLOBALISE_EXPLAIN' => 'To switch this topic back from being global to a normal topic, you need to select the forum you wish this topic to be displayed.', + 'UNSUPPORTED_CHARACTERS_MESSAGE' => 'Your message contains the following unsupported characters:<br />%s', + 'UNSUPPORTED_CHARACTERS_SUBJECT' => 'Your subject contains the following unsupported characters:<br />%s', 'UPDATE_COMMENT' => 'Update comment', 'URL_INVALID' => 'The URL you specified is invalid.', 'URL_NOT_FOUND' => 'The file specified could not be found.', diff --git a/phpBB/posting.php b/phpBB/posting.php index 60bb595da6..17eac71bd3 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1028,6 +1028,14 @@ if ($submit || $preview || $refresh) $error[] = $user->lang['EMPTY_SUBJECT']; } + // Check for out-of-bounds characters that are currently + // not supported by utf8_bin in MySQL + if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $post_data['post_subject'], $matches)) + { + $character_list = implode('<br />', $matches[0]); + $error[] = $user->lang('UNSUPPORTED_CHARACTERS_SUBJECT', $character_list); + } + $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0; if ($post_data['poll_option_text'] && diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 2611ef7bf1..fd802eed45 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -36,4 +36,27 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } + + public function test_unsupported_characters() + { + $this->login(); + + $this->add_lang('posting'); + + self::create_post(2, + 1, + 'Unsupported characters', + "This is a test with these weird characters: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6", + array(), + 'Your message contains the following unsupported characters' + ); + + self::create_post(2, + 1, + "Unsupported: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6", + 'This is a test with emoji characters in the topic title.', + array(), + 'Your subject contains the following unsupported characters' + ); + } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e4504a5f8d..fde6a6a4ff 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -1076,9 +1076,17 @@ class phpbb_functional_test_case extends phpbb_test_case if ($expected !== '') { - $this->assertContainsLang($expected, $crawler->filter('html')->text()); + if (isset($this->lang[$expected])) + { + $this->assertContainsLang($expected, $crawler->filter('html')->text()); + } + else + { + $this->assertContains($expected, $crawler->filter('html')->text()); + } return null; } + $url = $crawler->selectLink($form_data['subject'])->link()->getUri(); return array( |