Skip to content

A platform for community discussion. Free, open, simple.

FIX: Use replacement icon class for all dot-namespaced icon IDs (#38713)

Régis Hanol298c0208e67a
diff --git a/frontend/discourse/app/lib/icon-library.js b/frontend/discourse/app/lib/icon-library.js
index 57f76b45244..245b81e1a63 100644
--- a/frontend/discourse/app/lib/icon-library.js
+++ b/frontend/discourse/app/lib/icon-library.js
@@ -120,11 +120,9 @@ export function registerIconRenderer(renderer) {
}
function iconClasses(icon, params) {
- // "notification." is invalid syntax for classes, use replacement instead
+ // dots are invalid syntax for classes, use replacement instead
const dClass =
- icon.replacementId && icon.id.includes("notification.")
- ? icon.replacementId
- : icon.id;
+ icon.replacementId && icon.id.includes(".") ? icon.replacementId : icon.id;
let classNames = `fa d-icon d-icon-${dClass} svg-icon fa-width-auto`;
diff --git a/frontend/discourse/tests/acceptance/sidebar-user-categories-section-test.js b/frontend/discourse/tests/acceptance/sidebar-user-categories-section-test.js
index 9e8f9b86dc5..9b3c2a6d3ae 100644
--- a/frontend/discourse/tests/acceptance/sidebar-user-categories-section-test.js
+++ b/frontend/discourse/tests/acceptance/sidebar-user-categories-section-test.js
@@ -483,7 +483,7 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
assert
.dom(
- `.sidebar-section-link-wrapper[data-category-id="${category3.id}"] .sidebar-section-link-prefix .prefix-badge[class*="d-icon-category.restricted"]`
+ `.sidebar-section-link-wrapper[data-category-id="${category3.id}"] .sidebar-section-link-prefix .prefix-badge[class*="d-icon-lock"]`
)
.exists(
"category3 section link is rendered with lock prefix badge icon as it is read restricted"
diff --git a/frontend/discourse/tests/acceptance/user-menu-test.js b/frontend/discourse/tests/acceptance/user-menu-test.js
index b8b20498aaf..f49a6195eec 100644
--- a/frontend/discourse/tests/acceptance/user-menu-test.js
+++ b/frontend/discourse/tests/acceptance/user-menu-test.js
@@ -478,7 +478,7 @@ acceptance("User menu", function (needs) {
"drafts link has the right label with count of the user's drafts"
);
assert
- .dom("#quick-access-profile ul li.drafts a .d-icon-user_menu\\.drafts")
+ .dom("#quick-access-profile ul li.drafts a .d-icon-pencil")
.exists("drafts link has the right icon");
assert
diff --git a/frontend/discourse/tests/unit/lib/icon-library-test.js b/frontend/discourse/tests/unit/lib/icon-library-test.js
index 685b61dd444..05061bd5b3f 100644
--- a/frontend/discourse/tests/unit/lib/icon-library-test.js
+++ b/frontend/discourse/tests/unit/lib/icon-library-test.js
@@ -26,6 +26,21 @@ module("Unit | Utility | icon-library", function (hooks) {
assert.false(iconHTML(iconC).includes(" "), "trims whitespace");
});
+ test("uses replacement id for class when icon id contains dots", function (assert) {
+ let html = iconHTML("user_menu.replies");
+ assert.true(html.includes("d-icon-reply"), "uses replacement id for class");
+ assert.false(
+ html.includes("d-icon-user_menu.replies"),
+ "does not use dotted id for class"
+ );
+
+ html = iconHTML("notification.replied");
+ assert.true(
+ html.includes("d-icon-reply"),
+ "uses replacement id for notification icons"
+ );
+ });
+
test("escape icon names, classes, titles and aria-label", function (assert) {
let html = iconHTML("'<img src='x'>", {
translatedTitle: "'<script src='y'>",
diff --git a/spec/system/page_objects/components/review/topic_link.rb b/spec/system/page_objects/components/review/topic_link.rb
index 98920ed6aa2..ba18ff15bfc 100644
--- a/spec/system/page_objects/components/review/topic_link.rb
+++ b/spec/system/page_objects/components/review/topic_link.rb
@@ -7,7 +7,7 @@ module PageObjects
WRAPPER_CSS = ".review-item__meta-topic-title"
def has_closed_topic_status?
- within(WRAPPER_CSS) { has_css?(".topic-status [class*='d-icon-topic.closed']") }
+ within(WRAPPER_CSS) { has_css?(".topic-status [class*='d-icon-lock']") }
end
def has_topic_link?(topic_title:, post_url:)
diff --git a/spec/system/page_objects/components/topic_list.rb b/spec/system/page_objects/components/topic_list.rb
index 7b3fadf9cdb..05484508d35 100644
--- a/spec/system/page_objects/components/topic_list.rb
+++ b/spec/system/page_objects/components/topic_list.rb
@@ -131,7 +131,7 @@ module PageObjects
private
def topic_list_item_closed(topic)
- "#{topic_list_item_class(topic)} .topic-statuses .topic-status svg[class*='d-icon-topic.closed']"
+ "#{topic_list_item_class(topic)} .topic-statuses .topic-status svg[class*='d-icon-lock']"
end
def topic_list_item_unread_badge(topic)
diff --git a/themes/horizon/scss/categories-view.scss b/themes/horizon/scss/categories-view.scss
index 2e534bc71c4..e90b95660e1 100644
--- a/themes/horizon/scss/categories-view.scss
+++ b/themes/horizon/scss/categories-view.scss
@@ -63,7 +63,7 @@
align-items: center;
font-size: var(--font-up-1-rem);
- .d-icon:first-of-type:not([class*="d-icon-category.restricted"]),
+ .d-icon:first-of-type:not([class*="d-icon-lock"]),
&.--style-square::before,
&.--style-emoji .emoji {
width: 1.25em;
@@ -76,7 +76,7 @@
}
}
- [class*="d-icon-category.restricted"] {
+ [class*="d-icon-lock"] {
order: 1;
}
}
@@ -330,7 +330,7 @@
font-size: var(--font-up-1-rem);
}
- .d-icon:not([class*="d-icon-category.restricted"]),
+ .d-icon:not([class*="d-icon-lock"]),
img.emoji {
aspect-ratio: 1 / 1;
height: auto;