From 828e995f032d631ba9f8176524c4d3ff2e5c8ee7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 14 Jun 2014 11:34:32 +0200 Subject: [PATCH 1/2] [ticket/12705] Break calling make_clickable with a different server_url PHPBB3-12705 --- tests/text_processing/make_clickable_test.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/text_processing/make_clickable_test.php b/tests/text_processing/make_clickable_test.php index 2c78391453..95e304dd97 100644 --- a/tests/text_processing/make_clickable_test.php +++ b/tests/text_processing/make_clickable_test.php @@ -104,5 +104,50 @@ class phpbb_text_processing_make_clickable_test extends phpbb_test_case $this->assertEquals($expected, $result, $label); } + public function make_clickable_mixed_serverurl_data() + { + $urls = array( + 'http://thisdomain.org' => array('tag' => 'm', 'url' => false, 'text' => false), + 'http://thisdomain.org/' => array('tag' => 'm', 'url' => false, 'text' => false), + 'http://thisdomain.org/1' => array('tag' => 'm', 'url' => false, 'text' => false), + 'http://thisdomain.org/path/some?query=abc#test' => array('tag' => 'm', 'url' => false, 'text' => false), + + 'https://www.phpbb.com' => array('tag' => 'm', 'url' => false, 'text' => false), + 'https://www.phpbb.com/' => array('tag' => 'm', 'url' => false, 'text' => false), + 'https://www.phpbb.com/1' => array('tag' => 'l', 'url' => false, 'text' => '1'), + 'https://www.phpbb.com/path/some?query=abc#test' => array('tag' => 'l', 'url' => false, 'text' => 'path/some?query=abc#test'), + ); + + $test_data = array(); + + // run the test for each combination + foreach ($urls as $url => $url_type) + { + // false means it's the same as the url, less typing + $url_type['url'] = ($url_type['url']) ? $url_type['url'] : $url; + $url_type['text'] = ($url_type['text']) ? $url_type['text'] : $url; + + $class = ($url_type['tag'] === 'l') ? 'postlink-local' : 'postlink'; + + // replace the url with the desired output format + $output = '' . $url_type['text'] . ''; + + $test_data[] = array($url, $output); + } + + return $test_data; + } + + /** + * @dataProvider make_clickable_mixed_serverurl_data + */ + public function test_make_clickable_mixed_serverurl($input, $expected) + { + $result = make_clickable($input, 'https://www.phpbb.com'); + + $label = 'Making text clickable: ' . $input; + $this->assertEquals($expected, $result, $label); + } + } From f1adf82aeac76601bcf0a32e8be0298624520b35 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 14 Jun 2014 11:35:27 +0200 Subject: [PATCH 2/2] [ticket/12705] Store the regular expression matches based on server_url PHPBB3-12705 --- phpBB/includes/functions_content.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 72fca905e0..74b3e0c70f 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -773,44 +773,47 @@ function make_clickable($text, $server_url = false, $class = 'postlink') static $static_class; static $magic_url_match_args; - if (!is_array($magic_url_match_args) || $static_class != $class) + if (!isset($magic_url_match_args[$server_url]) || $static_class != $class) { $static_class = $class; $class = ($static_class) ? ' class="' . $static_class . '"' : ''; $local_class = ($static_class) ? ' class="' . $static_class . '-local"' : ''; - $magic_url_match_args = array(); + if (!is_array($magic_url_match_args)) + { + $magic_url_match_args = array(); + } // relative urls for this board - $magic_url_match_args[] = array( + $magic_url_match_args[$server_url][] = array( '#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#i', MAGIC_URL_LOCAL, $local_class, ); // matches a xxxx://aaaaa.bbb.cccc. ... - $magic_url_match_args[] = array( + $magic_url_match_args[$server_url][] = array( '#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#i', MAGIC_URL_FULL, $class, ); // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing - $magic_url_match_args[] = array( + $magic_url_match_args[$server_url][] = array( '#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#i', MAGIC_URL_WWW, $class, ); // matches an email@domain type address at the start of a line, or after a space or after what might be a BBCode. - $magic_url_match_args[] = array( + $magic_url_match_args[$server_url][] = array( '/(^|[\n\t (>])(' . get_preg_expression('email') . ')/i', MAGIC_URL_EMAIL, '', ); } - foreach ($magic_url_match_args as $magic_args) + foreach ($magic_url_match_args[$server_url] as $magic_args) { if (preg_match($magic_args[0], $text, $matches)) {