diff --git a/CHANGELOG b/CHANGELOG index ab047731ec..cd120b2dfa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 9023959978..9fbfd2d629 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -213,7 +213,6 @@ class Smilies return $text; } - $text = preg_replace_callback('/
(.*?)<\/pre>/ism'  , 'self::encode', $text);
 		$text = preg_replace_callback('/(.*?)<\/code>/ism', 'self::encode', $text);
 
 		if ($no_images) {
@@ -231,7 +230,6 @@ class Smilies
 		$text = preg_replace_callback('/<(3+)/', 'self::pregHeart', $text);
 		$text = self::strOrigReplace($smilies['texts'], $smilies['icons'], $text);
 
-		$text = preg_replace_callback('/
(.*?)<\/pre>/ism', 'self::decode', $text);
 		$text = preg_replace_callback('/(.*?)<\/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 '' . Strings::base64UrlEncode($m[1]) . '';
 	}
 
 	/**
@@ -255,7 +253,7 @@ class Smilies
 	 */
 	private static function decode($m)
 	{
-		return(str_replace($m[1], Strings::base64UrlDecode($m[1]), $m[0]));
+		return '' . Strings::base64UrlDecode($m[1]) . '';
 	}
 
 
diff --git a/tests/src/Content/SmiliesTest.php b/tests/src/Content/SmiliesTest.php
new file mode 100644
index 0000000000..40d126e005
--- /dev/null
+++ b/tests/src/Content/SmiliesTest.php
@@ -0,0 +1,69 @@
+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' => '/',
+				'smilies' => ['texts' => [], 'icons' => []],
+				'expected' => '/',
+			],
+			'bug-6933-2' => [
+				'data' => 'code',
+				'smilies' => ['texts' => [], 'icons' => []],
+				'expected' => '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);
+	}
+}