mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-03 14:17:56 +02:00
Merge pull request #2588 from nickvergessen/ticket/12705
Ticket/12705 Fix make_clickable when called with different server_urls
This commit is contained in:
commit
7ee3e3f73f
@ -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))
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user