aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/functions_content.php17
-rw-r--r--tests/text_processing/make_clickable_test.php45
2 files changed, 55 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))
{
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['tag'] . ' --><a class="' . $class . '" href="' . $url_type['url'] . '">' . $url_type['text'] . '</a><!-- ' . $url_type['tag'] . ' -->';
+
+ $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);
+ }
+
}