Skip to content

Commit 8a8f945

Browse files
committed
DEV: Remove Handlebars dependency
Raw-handlebars will be removed from Discourse core imminently (discourse/discourse#32081) The usage in `custom-user-selector` seemed like it was expecting SafeString to actually do something to escape user input. It doesn't actually do any processing to the string. So I removed it, and added `escapeExpression` around the user input instead. The usage in wizard-char-counter can be easily replaced with Ember's `htmlSafe` helper
1 parent d2ff1b5 commit 8a8f945

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

assets/javascripts/discourse/components/custom-user-selector.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { isEmpty } from "@ember/utils";
2-
import Handlebars from "handlebars";
32
import $ from "jquery";
43
import TextField from "discourse/components/text-field";
54
import { renderAvatar } from "discourse/helpers/user-avatar";
6-
import userSearch from "discourse/lib/user-search";
75
import {
86
default as computed,
97
observes,
10-
} from "discourse-common/utils/decorators";
11-
import I18n from "I18n";
8+
} from "discourse/lib/decorators";
9+
import userSearch from "discourse/lib/user-search";
10+
import { escapeExpression } from "discourse/lib/utilities";
11+
import { i18n } from "discourse-i18n";
1212

1313
const template = function (params) {
1414
const options = params.options;
@@ -17,11 +17,11 @@ const template = function (params) {
1717
if (options.users) {
1818
html += "<ul>";
1919
options.users.forEach((u) => {
20-
html += `<li><a href title="${u.name}">`;
20+
html += `<li><a href title="${escapeExpression(u.name)}">`;
2121
html += renderAvatar(u, { imageSize: "tiny" });
22-
html += `<span class='username'>${u.username}</span>`;
22+
html += `<span class='username'>${escapeExpression(u.username)}</span>`;
2323
if (u.name) {
24-
html += `<span class='name'>${u.name}</span>`;
24+
html += `<span class='name'>${escapeExpression(u.name)}</span>`;
2525
}
2626
html += `</a></li>`;
2727
});
@@ -30,7 +30,7 @@ const template = function (params) {
3030

3131
html += "</div>";
3232

33-
return new Handlebars.SafeString(html).string;
33+
return html;
3434
};
3535

3636
export default TextField.extend({
@@ -42,7 +42,7 @@ export default TextField.extend({
4242

4343
@computed("placeholderKey")
4444
placeholder(placeholderKey) {
45-
return placeholderKey ? I18n.t(placeholderKey) : "";
45+
return placeholderKey ? i18n(placeholderKey) : "";
4646
},
4747

4848
@observes("usernames")

assets/javascripts/discourse/helpers/wizard-char-counter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Handlebars from "handlebars";
21
import I18n from "I18n";
2+
import { htmlSafe } from "@ember/template";
33

44
export default function wizardCharCounter(body, maxLength) {
55
let bodyLength = body ? body.length : 0;
@@ -17,5 +17,5 @@ export default function wizardCharCounter(body, maxLength) {
1717
})}</div>`;
1818
}
1919

20-
return new Handlebars.SafeString(finalString);
20+
return htmlSafe(finalString);
2121
}

0 commit comments

Comments
 (0)