From 4f84ed67230a9dad75f797eaf1e56b31680669bf Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 29 Sep 2022 14:44:41 +0800 Subject: [PATCH] FIX: Use `Category#category_text` for sidebar title (#18411) Previously we used `Category#category_excerpt` but the excerpt keeps the HTML entities around if present and we can't really display HTML in the title of a link. --- .../category-section-link.js | 2 +- .../sidebar-user-categories-section-test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js index 5a9441909e2..365aa1ead54 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/categories-section/category-section-link.js @@ -41,7 +41,7 @@ export default class CategorySectionLink { } get title() { - return this.category.description_excerpt; + return this.category.description_text; } get text() { diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js index 4586df9ed26..8737c9eb9ed 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js @@ -254,6 +254,25 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) { ); }); + test("category section link have the right title", async function (assert) { + const categories = Site.current().categories; + + // Category with link HTML tag in description + const category = categories.find((c) => c.id === 28); + + updateCurrentUser({ + sidebar_category_ids: [category.id], + }); + + await visit("/"); + + assert.strictEqual( + query(`.sidebar-section-link-${category.slug}`).title, + category.description_text, + "category description without HTML entity is used as the link's title" + ); + }); + test("visiting category discovery new route", async function (assert) { const { category1 } = setupUserSidebarCategories();