From 2fb443ac3d75156ea57d5366c4ea4f23dac0cd8b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Mar 2019 00:16:18 -0400 Subject: [PATCH 1/3] Fix wrong code blocks escaping in Content\Smilies --- src/Content/Smilies.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 902395997..9fbfd2d62 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]) . '';
 	}
 
 

From 86bb26cfe559b18b353b885e3e66a086e38d4d29 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan 
Date: Mon, 25 Mar 2019 00:16:35 -0400
Subject: [PATCH 2/3] Add smilies code blocks issue to CHANGELOG

---
 CHANGELOG | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG b/CHANGELOG
index ab047731e..cd120b2df 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]

From 9210767518b5231d21db3e5003012ae3affff850 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan 
Date: Mon, 25 Mar 2019 21:52:35 -0400
Subject: [PATCH 3/3] Add cover code block encoding edge case in smilies
 replacement tests

---
 tests/src/Content/SmiliesTest.php | 69 +++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 tests/src/Content/SmiliesTest.php

diff --git a/tests/src/Content/SmiliesTest.php b/tests/src/Content/SmiliesTest.php
new file mode 100644
index 000000000..40d126e00
--- /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);
+	}
+}