aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/phpbb/textformatter/s9e/utils.php37
-rw-r--r--phpBB/phpbb/textformatter/utils_interface.php12
-rw-r--r--phpBB/posting.php6
-rw-r--r--tests/functional/posting_test.php14
-rw-r--r--tests/text_formatter/s9e/utils_test.php51
5 files changed, 119 insertions, 1 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php
index e21dedecc4..fe33c04da3 100644
--- a/phpBB/phpbb/textformatter/s9e/utils.php
+++ b/phpBB/phpbb/textformatter/s9e/utils.php
@@ -35,6 +35,43 @@ class utils implements \phpbb\textformatter\utils_interface
}
/**
+ * Return given string between quotes
+ *
+ * Will use either single- or double- quotes depending on whichever requires to be escaped.
+ * Quotes and backslashes are escaped with backslashes where necessary
+ *
+ * @param string $str Original string
+ * @return string Escaped string within quotes
+ */
+ protected function enquote($str)
+ {
+ $quote = (strpos($str, '"') === false || strpos($str, "'") !== false) ? '"' : "'";
+
+ return $quote . addcslashes($str, '\\' . $quote) . $quote;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function generate_quote($text, array $attributes = array())
+ {
+ $quote = '[quote';
+ if (isset($attributes['author']))
+ {
+ // Add the author as the BBCode's default attribute
+ $quote .= '=' . $this->enquote($attributes['author']);
+ unset($attributes['author']);
+ }
+ foreach ($attributes as $name => $value)
+ {
+ $quote .= ' ' . $name . '=' . $this->enquote($value);
+ }
+ $quote .= ']' . $text . '[/quote]';
+
+ return $quote;
+ }
+
+ /**
* Get a list of quote authors, limited to the outermost quotes
*
* @param string $xml Parsed text
diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php
index 6d3fd13021..41a6ba2345 100644
--- a/phpBB/phpbb/textformatter/utils_interface.php
+++ b/phpBB/phpbb/textformatter/utils_interface.php
@@ -29,6 +29,18 @@ interface utils_interface
public function clean_formatting($text);
/**
+ * Create a quote block for given text
+ *
+ * Possible attributes:
+ * - author
+ *
+ * @param string $text Quote's text
+ * @param array $attributes Quote's attributes
+ * @return string Quote block to be used in a new post/text
+ */
+ public function generate_quote($text, array $attributes = array());
+
+ /**
* Get a list of quote authors, limited to the outermost quotes
*
* @param string $text Parsed text
diff --git a/phpBB/posting.php b/phpBB/posting.php
index a4fb4d7a8d..4d52da2567 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -1597,7 +1597,11 @@ if ($generate_quote)
{
if ($config['allow_bbcode'])
{
- $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
+ $message_parser->message = $phpbb_container->get('text_formatter.utils')->generate_quote(
+ censor_text(trim($message_parser->message)),
+ array('author' => $post_data['quote_username'])
+ );
+ $message_parser->message .= "\n";
}
else
{
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
index 5c083aef37..8677237772 100644
--- a/tests/functional/posting_test.php
+++ b/tests/functional/posting_test.php
@@ -72,6 +72,20 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
$this->assertContains('😀', $crawler->text());
}
+ public function test_quote()
+ {
+ $text = 'Test post </textarea>"\' &&amp;amp;';
+ $expected = '[quote="admin"]' . $text . '[/quote]';
+
+ $this->login();
+ $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic');
+ $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text);
+
+ $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}");
+
+ $this->assertContains($expected, $crawler->filter('textarea#message')->text());
+ }
+
/**
* @testdox max_quote_depth is applied to the text populating the posting form
*/
diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php
index b1b937709c..3c92965b49 100644
--- a/tests/text_formatter/s9e/utils_test.php
+++ b/tests/text_formatter/s9e/utils_test.php
@@ -109,6 +109,57 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case
}
/**
+ * @dataProvider get_generate_quote_tests
+ */
+ public function test_generate_quote($text, $params, $expected)
+ {
+ $container = $this->get_test_case_helpers()->set_s9e_services();
+ $utils = $container->get('text_formatter.utils');
+
+ $this->assertSame($expected, $utils->generate_quote($text, $params));
+ }
+
+ public function get_generate_quote_tests()
+ {
+ return array(
+ array(
+ '...',
+ array(),
+ '[quote]...[/quote]',
+ ),
+ array(
+ '...',
+ array('author' => 'Brian Kibler'),
+ '[quote="Brian Kibler"]...[/quote]',
+ ),
+ array(
+ '...',
+ array('author' => 'Brian "Brian Kibler" Kibler of Brian Kibler Gaming'),
+ '[quote=\'Brian "Brian Kibler" Kibler of Brian Kibler Gaming\']...[/quote]',
+ ),
+ array(
+ '...',
+ array('author' => "Brian Kibler Gaming's Brian Kibler"),
+ '[quote="Brian Kibler Gaming\'s Brian Kibler"]...[/quote]',
+ ),
+ array(
+ '...',
+ array('author' => "\\\"'"),
+ '[quote="\\\\\\"\'"]...[/quote]',
+ ),
+ array(
+ '...',
+ array(
+ 'author' => 'user',
+ 'post_id' => 123,
+ 'url' => 'http://example.org'
+ ),
+ '[quote="user" post_id="123" url="http://example.org"]...[/quote]',
+ ),
+ );
+ }
+
+ /**
* @dataProvider get_remove_bbcode_tests
*/
public function test_remove_bbcode($original, $name, $depth, $expected)