Merge pull request #6933 from MrPetovan/bug/smilies-wrong-escape

Fix wrong code block escaping in Smilies
This commit is contained in:
Philipp 2019-03-26 07:25:41 +01:00 committed by GitHub
commit 22f884484a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 4 deletions

View file

@ -6,6 +6,7 @@ Version 2019.06 (UNRELEASED) (2019-06-?)
Fixed the timezone of Friendica logs [nupplaphil]
Fixed tag completion painfully slow [AlfredSK]
Fixed a regression in notifications [MrPetovan]
Fixed an issue with smilies and code blocks [MrPetovan]
General Code cleaning and restructuring [nupplaphil]
Added frio color scheme sharing [JeroenED]
Added syslog and stream Logger [nupplaphil]

View file

@ -213,7 +213,6 @@ class Smilies
return $text;
}
$text = preg_replace_callback('/<pre>(.*?)<\/pre>/ism' , 'self::encode', $text);
$text = preg_replace_callback('/<code>(.*?)<\/code>/ism', 'self::encode', $text);
if ($no_images) {
@ -231,7 +230,6 @@ class Smilies
$text = preg_replace_callback('/&lt;(3+)/', 'self::pregHeart', $text);
$text = self::strOrigReplace($smilies['texts'], $smilies['icons'], $text);
$text = preg_replace_callback('/<pre>(.*?)<\/pre>/ism', 'self::decode', $text);
$text = preg_replace_callback('/<code>(.*?)<\/code>/ism', 'self::decode', $text);
return $text;
@ -244,7 +242,7 @@ class Smilies
*/
private static function encode($m)
{
return(str_replace($m[1], Strings::base64UrlEncode($m[1]), $m[0]));
return '<code>' . Strings::base64UrlEncode($m[1]) . '</code>';
}
/**
@ -255,7 +253,7 @@ class Smilies
*/
private static function decode($m)
{
return(str_replace($m[1], Strings::base64UrlDecode($m[1]), $m[0]));
return '<code>' . Strings::base64UrlDecode($m[1]) . '</code>';
}

View file

@ -0,0 +1,69 @@
<?php
/**
* Created by PhpStorm.
* User: benlo
* Date: 25/03/19
* Time: 21:36
*/
namespace Friendica\Test\src\Content;
use Friendica\Content\Smilies;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\L10nMockTrait;
use Friendica\Test\Util\VFSTrait;
class SmiliesTest extends MockedTest
{
use VFSTrait;
use AppMockTrait;
use L10nMockTrait;
protected function setUp()
{
parent::setUp();
$this->setUpVfsDir();
$this->mockApp($this->root);
$this->app->videowidth = 425;
$this->app->videoheight = 350;
$this->configMock->shouldReceive('get')
->with('system', 'no_smilies')
->andReturn(false);
$this->configMock->shouldReceive('get')
->with(false, 'system', 'no_smilies')
->andReturn(false);
}
public function dataLinks()
{
return [
/** @see https://github.com/friendica/friendica/pull/6933 */
'bug-6933-1' => [
'data' => '<code>/</code>',
'smilies' => ['texts' => [], 'icons' => []],
'expected' => '<code>/</code>',
],
'bug-6933-2' => [
'data' => '<code>code</code>',
'smilies' => ['texts' => [], 'icons' => []],
'expected' => '<code>code</code>',
],
];
}
/**
* Test replace smilies in different texts
* @dataProvider dataLinks
*
* @param string $text Test string
* @param array $smilies List of smilies to replace
* @param string $expected Expected result
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function testReplaceFromArray($text, $smilies, $expected)
{
$output = Smilies::replaceFromArray($text, $smilies);
$this->assertEquals($expected, $output);
}
}