From 89f70673779f1908c8f000c5c053bb377e253254 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 9 Jun 2014 15:55:04 +0200 Subject: [PATCH 1/4] [ticket/11711] Inform user of unsupported characters while posting PHPBB3-11711 --- phpBB/includes/message_parser.php | 13 +++++++++++ phpBB/language/en/posting.php | 1 + tests/functional/posting_test.php | 38 +++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 6d3907880e..eed892986e 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1194,6 +1194,19 @@ class parse_message extends bbcode_firstpass } } + // Check for out-of-bounds characters that are currently + // not supported by utf8_bin + if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $this->message, $matches)) + { + $character_list = ''; + foreach ($matches[0] as $cur_match) + { + $character_list .= $cur_match . '
'; + } + $this->warn_msg[] = $user->lang('UNSUPPORTED_CHARACTERS', $character_list); + return (!$update_this_message) ? $return_message : $this->warn_msg; + } + // 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..ac08b27943 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -256,6 +256,7 @@ $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' => 'Your message contains the following unsupported characters:
%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/tests/functional/posting_test.php b/tests/functional/posting_test.php index 2611ef7bf1..430a6496a0 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -36,4 +36,42 @@ 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'); + + $crawler = self::request('GET', "posting.php?mode=reply&f=2&t=1&sid={$this->sid}"); + + $form = $crawler->selectButton('Submit')->form(); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->attr('name'), 'value' => $node->attr('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + $form_data += array( + 'subject' => 'Unsupported characters', + 'message' => 'This is a test with these weird characters: 👅👅👅', + 'post' => true, + ); + $crawler = self::request('POST', "posting.php?mode=reply&f=2&t=1&sid={$this->sid}", $form_data); + + $this->assertContains('Your message contains the following unsupported characters', $crawler->text()); + } } From b8151b1299c02506ffa0d665461d85e32cd4cd10 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 9 Jun 2014 18:56:13 +0200 Subject: [PATCH 2/4] [ticket/11711] Improve checks for unsupported characters and check subject PHPBB3-11711 --- phpBB/includes/message_parser.php | 10 +++------- phpBB/language/en/posting.php | 3 ++- phpBB/posting.php | 8 ++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index eed892986e..8965b50667 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1198,13 +1198,9 @@ class parse_message extends bbcode_firstpass // not supported by utf8_bin if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $this->message, $matches)) { - $character_list = ''; - foreach ($matches[0] as $cur_match) - { - $character_list .= $cur_match . '
'; - } - $this->warn_msg[] = $user->lang('UNSUPPORTED_CHARACTERS', $character_list); - return (!$update_this_message) ? $return_message : $this->warn_msg; + $character_list = implode('
', $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. diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index ac08b27943..e8a8643cfd 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -256,7 +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' => 'Your message contains the following unsupported characters:
%s', + 'UNSUPPORTED_CHARACTERS_MESSAGE' => 'Your message contains the following unsupported characters:
%s', + 'UNSUPPORTED_CHARACTERS_SUBJECT' => 'Your subject contains the following unsupported characters:
%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..fc407caf69 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 + if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $post_data['post_subject'], $matches)) + { + $character_list = implode('
', $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'] && From 65884bf2bd754343410a5b3d8b4eea2343dc42e9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 9 Jun 2014 18:57:05 +0200 Subject: [PATCH 3/4] [ticket/11711] Reduce size of tests and also test topic titles PHPBB3-11711 --- tests/functional/posting_test.php | 41 ++++++------------- .../phpbb_functional_test_case.php | 7 +++- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 430a6496a0..b0a2f069e1 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -43,35 +43,18 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $this->add_lang('posting'); - $crawler = self::request('GET', "posting.php?mode=reply&f=2&t=1&sid={$this->sid}"); + 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'); - $form = $crawler->selectButton('Submit')->form(); - - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->attr('name'), 'value' => $node->attr('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - $form_data += array( - 'subject' => 'Unsupported characters', - 'message' => 'This is a test with these weird characters: 👅👅👅', - 'post' => true, - ); - $crawler = self::request('POST', "posting.php?mode=reply&f=2&t=1&sid={$this->sid}", $form_data); - - $this->assertContains('Your message contains the following unsupported characters', $crawler->text()); + 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 182ffaaaf7..c0127c50c9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -996,11 +996,16 @@ class phpbb_functional_test_case extends phpbb_test_case // Instead, I send it as a request with the submit button "post" set to true. $crawler = self::request('POST', $posting_url, $form_data); - if ($expected !== '') + if ($expected !== '' && isset($this->lang[$expected])) { $this->assertContainsLang($expected, $crawler->filter('html')->text()); return null; } + else if ($expected !== '') + { + $this->assertContains($expected, $crawler->filter('html')->text()); + return null; + } $url = $crawler->selectLink($form_data['subject'])->link()->getUri(); return array( From 5ee7f20f4ee110c2ae0b122e9efbd4fabf669581 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 10 Jun 2014 15:51:25 +0200 Subject: [PATCH 4/4] [ticket/11711] Improve coding and comments of character check PHPBB3-11711 --- phpBB/includes/message_parser.php | 2 +- phpBB/posting.php | 2 +- tests/functional/posting_test.php | 6 ++++-- .../phpbb_functional_test_case.php | 17 ++++++++++------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 8965b50667..9d95620e0f 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1195,7 +1195,7 @@ class parse_message extends bbcode_firstpass } // Check for out-of-bounds characters that are currently - // not supported by utf8_bin + // not supported by utf8_bin in MySQL if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $this->message, $matches)) { $character_list = implode('
', $matches[0]); diff --git a/phpBB/posting.php b/phpBB/posting.php index fc407caf69..17eac71bd3 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1029,7 +1029,7 @@ if ($submit || $preview || $refresh) } // Check for out-of-bounds characters that are currently - // not supported by utf8_bin + // not supported by utf8_bin in MySQL if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $post_data['post_subject'], $matches)) { $character_list = implode('
', $matches[0]); diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index b0a2f069e1..fd802eed45 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -48,13 +48,15 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case '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'); + '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'); + '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 c0127c50c9..f2c2c8f181 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -996,16 +996,19 @@ class phpbb_functional_test_case extends phpbb_test_case // Instead, I send it as a request with the submit button "post" set to true. $crawler = self::request('POST', $posting_url, $form_data); - if ($expected !== '' && isset($this->lang[$expected])) + if ($expected !== '') { - $this->assertContainsLang($expected, $crawler->filter('html')->text()); - return null; - } - else if ($expected !== '') - { - $this->assertContains($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(