URL encode links when a redirector is set.
Fixes #328 - URL encode links when a redirector is set * WARNING - template edit - new variable available : "real_url" Contains the final real url (redirected or any other change on original URL) * Don't redirect shaares link in RSS/Atom. * Affects links shaared in description. * Move text2clickable and keepMultipleSpaces to Utils.php + unit test UPDATE: * keepMultipleSpaces renamed to space2nbsp * space2nbsp improved to handle single space at line beginning * links in text description aren't 'nofollow' anymore
This commit is contained in:
parent
986afb752b
commit
90e5bd65c9
10 changed files with 160 additions and 37 deletions
tests
|
@ -511,4 +511,27 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
sizeof(self::$publicLinkDB->filterFullText('free software'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test real_url without redirector.
|
||||
*/
|
||||
public function testLinkRealUrlWithoutRedirector()
|
||||
{
|
||||
$db = new LinkDB(self::$testDatastore, false, false);
|
||||
foreach($db as $link) {
|
||||
$this->assertEquals($link['url'], $link['real_url']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test real_url with redirector.
|
||||
*/
|
||||
public function testLinkRealUrlWithRedirector()
|
||||
{
|
||||
$redirector = 'http://redirector.to?';
|
||||
$db = new LinkDB(self::$testDatastore, false, false, $redirector);
|
||||
foreach($db as $link) {
|
||||
$this->assertStringStartsWith($redirector, $link['real_url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,4 +187,41 @@ class UtilsTest extends PHPUnit_Framework_TestCase
|
|||
is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text2clickable without a redirector being set.
|
||||
*/
|
||||
public function testText2clickableWithoutRedirector()
|
||||
{
|
||||
$text = 'stuff http://hello.there/is=someone#here otherstuff';
|
||||
$expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff';
|
||||
$processedText = text2clickable($text, '');
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text2clickable a redirector set.
|
||||
*/
|
||||
public function testText2clickableWithRedirector()
|
||||
{
|
||||
$text = 'stuff http://hello.there/is=someone#here otherstuff';
|
||||
$redirector = 'http://redirector.to';
|
||||
$expectedText = 'stuff <a href="'.
|
||||
$redirector .
|
||||
urlencode('http://hello.there/is=someone#here') .
|
||||
'">http://hello.there/is=someone#here</a> otherstuff';
|
||||
$processedText = text2clickable($text, $redirector);
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test testSpace2nbsp.
|
||||
*/
|
||||
public function testSpace2nbsp()
|
||||
{
|
||||
$text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?';
|
||||
$expectedText = ' Are you thrilled by flags ?'. PHP_EOL .' Really?';
|
||||
$processedText = space2nbsp($text);
|
||||
$this->assertEquals($expectedText, $processedText);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class PlugQrcodeTest extends PHPUnit_Framework_TestCase
|
|||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'url' => $str,
|
||||
'real_url' => $str,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -39,7 +39,7 @@ class PlugQrcodeTest extends PHPUnit_Framework_TestCase
|
|||
$link = $data['links'][0];
|
||||
// data shouldn't be altered
|
||||
$this->assertEquals($str, $data['title']);
|
||||
$this->assertEquals($str, $link['url']);
|
||||
$this->assertEquals($str, $link['real_url']);
|
||||
|
||||
// plugin data
|
||||
$this->assertEquals(1, count($link['link_plugin']));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue