From 0f9099dec62edafa61248e07a16ffc85499e17d6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 20 Mar 2023 21:33:39 +0000 Subject: [PATCH 1/2] Issue 12701: Fix Markdown problems with Quotes --- src/Content/Text/BBCode.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b72dcc3c4e..930b94ac46 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1567,8 +1567,13 @@ class BBCode "/\[[iz]mg\=(.*?)\](.*?)\[\/[iz]mg\]/ism", function ($matches) use ($simple_html, $uriid) { $matches[1] = self::proxyUrl($matches[1], $simple_html, $uriid); - $matches[2] = htmlspecialchars($matches[2], ENT_COMPAT); - return '' . $matches[2] . ''; + $alt = htmlspecialchars($matches[2], ENT_COMPAT); + // Fix for Markdown problems wirh Diaspora, see issue #12701 + if (($simple_html != self::DIASPORA) || strpos($matches[2], '"') === false) { + return '' . $alt . ''; + } else { + return '' . $alt . ''; + } }, $text ); From 7e6ba0b4d271735bbf7474fb75a7cf43b787b678 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 21 Mar 2023 04:20:03 +0000 Subject: [PATCH 2/2] Tests added --- src/Content/Text/BBCode.php | 2 +- tests/src/Content/Text/BBCodeTest.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 930b94ac46..a38d2de785 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1568,7 +1568,7 @@ class BBCode function ($matches) use ($simple_html, $uriid) { $matches[1] = self::proxyUrl($matches[1], $simple_html, $uriid); $alt = htmlspecialchars($matches[2], ENT_COMPAT); - // Fix for Markdown problems wirh Diaspora, see issue #12701 + // Fix for Markdown problems with Diaspora, see issue #12701 if (($simple_html != self::DIASPORA) || strpos($matches[2], '"') === false) { return '' . $alt . ''; } else { diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 6f8fdea2e6..74d34f5a5e 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -317,6 +317,14 @@ Karl Marx - Die ursprüngliche Akkumulation 'expected' => '&`&`', 'text' => '&[code]&[/code]', ], + 'bug-12701-quotes' => [ + 'expected' => '[![abc"fgh](https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png)](https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581)', + 'text' => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abc"fgh[/img][/url]' + ], + 'bug-12701-no-quotes' => [ + 'expected' => '[![abcfgh](https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png "abcfgh")](https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581)', + 'text' => '[url=https://domain.tld/photos/user/image/86912721086415cdc8e0a03226831581][img=https://domain.tld/photo/86912721086415cdc8e0a03226831581-1.png]abcfgh[/img][/url]' + ], ]; } @@ -331,7 +339,7 @@ Karl Marx - Die ursprüngliche Akkumulation * * @throws InternalServerErrorException */ - public function testToMarkdown(string $expected, string $text, $for_diaspora = false) + public function testToMarkdown(string $expected, string $text, $for_diaspora = true) { $actual = BBCode::toMarkdown($text, $for_diaspora);