From 2ce6f1125b340ad05d6cdd161ec930ba67f88d50 Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:09:51 +0530 Subject: [PATCH] fix: do not double-encode titles and authors when importing JSON (#9556) * fix: do not double-encode titles and authors when importing JSON FreshRSS exports titles and authors HTML-encoded, and the JSON import encoded them again since #9168, so restoring a ZIP export turned "Post & more" into "Post &amp; more". Decode before encoding. * Unit test * Reduce comments --------- Co-authored-by: Alexandre Alapetite --- app/Controllers/importExportController.php | 4 ++-- tests/app/Models/EntryTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index f8fa6ba22..b88f8ded4 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -516,7 +516,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { } $feed_id = $article_to_feed[$item['guid']]; - $author = is_string($item['author'] ?? null) ? Minz_Helper::htmlspecialchars_utf8($item['author']) : ''; + $author = is_string($item['author'] ?? null) ? Minz_Helper::htmlspecialchars_utf8(htmlspecialchars_decode($item['author'], ENT_QUOTES)) : ''; $is_starred = null; // null is used to preserve the current state if that item exists and is already starred $is_read = null; $tags = is_array($item['categories'] ?? null) ? $item['categories'] : []; @@ -560,7 +560,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { $url = Minz_Helper::htmlspecialchars_utf8(FreshRSS_http_Util::checkUrl($url) ?: ''); $title = is_string($item['title'] ?? null) ? $item['title'] : $url; - $title = Minz_Helper::htmlspecialchars_utf8($title); + $title = Minz_Helper::htmlspecialchars_utf8(htmlspecialchars_decode($title, ENT_QUOTES)); if (is_array($item['content'] ?? null) && is_string($item['content']['content'] ?? null)) { $content = $item['content']['content']; diff --git a/tests/app/Models/EntryTest.php b/tests/app/Models/EntryTest.php index 37874a909..75af92e69 100644 --- a/tests/app/Models/EntryTest.php +++ b/tests/app/Models/EntryTest.php @@ -94,4 +94,19 @@ final class EntryTest extends \PHPUnit\Framework\TestCase { self::assertStringContainsString('src="https://example.com/thumb.jpg"', $html); self::assertStringContainsString('Hello', $html); } + + /** ZIP/JSON export/import */ + public function test_toGReaderFreshRssExportRoundTripsEncoding(): void { + $feed = new FreshRSS_Feed('http://example.net/feed.xml', validate: false); + $feed->_id(1); + $feed->_name('Feed & me'); + + $entry = new FreshRSS_Entry(1, 'tag:example.net,2026:1', 'A & B', 'B & C', 'Hello', 'https://example.net/post-1', 1731312000); + $entry->_id('1731312000000000'); + $entry->_feed($feed); + + $item = $entry->toGReader('freshrss'); + self::assertSame('A & B', $item['title']); + self::assertSame('B & C', $item['author']); + } }